diff --git a/build.gradle b/build.gradle index 88e39d0..f2c8ee5 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:0.7.+" + classpath "com.android.tools.build:gradle:1.2.+" } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9b8ffdd..e7faee0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip diff --git a/library/build.gradle b/library/build.gradle index b8b9d9e..ee61c20 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,17 +1,22 @@ -apply plugin: 'android-library' +import com.android.builder.core.BuilderConstants + +apply plugin: 'com.android.library' android { - buildToolsVersion '19.0.0' - compileSdkVersion 19 + compileSdkVersion 22 + buildToolsVersion "22.0.1" defaultConfig { minSdkVersion 7 } + + defaultPublishConfig "release" } + android.libraryVariants.all { variant -> def name = variant.buildType.name - if (name.equals(com.android.builder.BuilderConstants.DEBUG)) { + if (name.equals(BuilderConstants.DEBUG)) { return; // Skip debug builds. } def task = project.tasks.create "jar${name.capitalize()}", Jar diff --git a/library/src/main/java/com/readystatesoftware/sqliteasset/SQLiteAssetHelper.java b/library/src/main/java/com/readystatesoftware/sqliteasset/SQLiteAssetHelper.java index ebee1c9..6071f33 100755 --- a/library/src/main/java/com/readystatesoftware/sqliteasset/SQLiteAssetHelper.java +++ b/library/src/main/java/com/readystatesoftware/sqliteasset/SQLiteAssetHelper.java @@ -33,21 +33,21 @@ import java.util.zip.ZipInputStream; /** - * A helper class to manage database creation and version management using + * A helper class to manage database creation and version management using * an application's raw asset files. - * - * This class provides developers with a simple way to ship their Android app - * with an existing SQLite database (which may be pre-populated with data) and - * to manage its initial creation and any upgrades required with subsequent + *
+ * This class provides developers with a simple way to ship their Android app + * with an existing SQLite database (which may be pre-populated with data) and + * to manage its initial creation and any upgrades required with subsequent * version releases. - * + * *This class makes it easy for {@link android.content.ContentProvider} * implementations to defer opening and upgrading the database until first use, * to avoid blocking application startup with long-running database upgrades. - * + *
*For examples see * https://github.com/jgilfelt/android-sqlite-asset-helper - * + *
*Note: this class assumes * monotonically increasing version numbers for upgrades. Also, there * is no concept of a database downgrade; installing a new version of @@ -76,26 +76,33 @@ public class SQLiteAssetHelper extends SQLiteOpenHelper { private int mForcedUpgradeVersion = 0; /** - * Create a helper object to create, open, and/or manage a database in + * Create a helper object to create, open, and/or manage a database in * a specified location. * This method always returns very quickly. The database is not actually * created or opened until one of {@link #getWritableDatabase} or * {@link #getReadableDatabase} is called. * - * @param context to use to open or create the database - * @param name of the database file + * @param context to use to open or create the database + * @param name of the database file * @param storageDirectory to store the database file upon creation; caller must - * ensure that the specified absolute path is available and can be written to - * @param factory to use for creating cursor objects, or null for the default - * @param version number of the database (starting at 1); if the database is older, - * SQL file(s) contained within the application assets folder will be used to - * upgrade the database + * ensure that the specified absolute path is available and can be + * written to + * @param factory to use for creating cursor objects, or null for the default + * @param version number of the database (starting at 1); if the database is older, + * SQL file(s) contained within the application assets folder will be + * used to + * upgrade the database */ - public SQLiteAssetHelper(Context context, String name, String storageDirectory, CursorFactory factory, int version) { + public SQLiteAssetHelper(Context context, String name, String storageDirectory, CursorFactory + factory, int version) { super(context, name, factory, version); - if (version < 1) throw new IllegalArgumentException("Version must be >= 1, was " + version); - if (name == null) throw new IllegalArgumentException("Database name cannot be null"); + if (version < 1) { + throw new IllegalArgumentException("Version must be >= 1, was " + version); + } + if (name == null) { + throw new IllegalArgumentException("Database name cannot be null"); + } mContext = context; mName = name; @@ -112,18 +119,18 @@ public SQLiteAssetHelper(Context context, String name, String storageDirectory, } /** - * Create a helper object to create, open, and/or manage a database in + * Create a helper object to create, open, and/or manage a database in * the application's default private data directory. * This method always returns very quickly. The database is not actually * created or opened until one of {@link #getWritableDatabase} or * {@link #getReadableDatabase} is called. * * @param context to use to open or create the database - * @param name of the database file + * @param name of the database file * @param factory to use for creating cursor objects, or null for the default * @param version number of the database (starting at 1); if the database is older, - * SQL file(s) contained within the application assets folder will be used to - * upgrade the database + * SQL file(s) contained within the application assets folder will be used to + * upgrade the database */ public SQLiteAssetHelper(Context context, String name, CursorFactory factory, int version) { this(context, name, null, factory, version); @@ -133,19 +140,19 @@ public SQLiteAssetHelper(Context context, String name, CursorFactory factory, in * Create and/or open a database that will be used for reading and writing. * The first time this is called, the database will be extracted and copied * from the application's assets folder. - * + *
*Once opened successfully, the database is cached, so you can * call this method every time you need to write to the database. * (Make sure to call {@link #close} when you no longer need the database.) * Errors such as bad permissions or a full disk may cause this method * to fail, but future attempts may succeed if the problem is fixed.
- * + * *Database upgrade may take a long time, you * should not call this method from the application main thread, including * from {@link android.content.ContentProvider#onCreate ContentProvider.onCreate()}. * - * @throws SQLiteException if the database cannot be opened for writing * @return a read/write database object valid until {@link #close} is called + * @throws SQLiteException if the database cannot be opened for writing */ @Override public synchronized SQLiteDatabase getWritableDatabase() { @@ -210,13 +217,18 @@ public synchronized SQLiteDatabase getWritableDatabase() { mIsInitializing = false; if (success) { if (mDatabase != null) { - try { mDatabase.close(); } catch (Exception e) { } + try { + mDatabase.close(); + } catch (Exception e) { + } //mDatabase.unlock(); } mDatabase = db; } else { //if (mDatabase != null) mDatabase.unlock(); - if (db != null) db.close(); + if (db != null) { + db.close(); + } } } @@ -230,15 +242,15 @@ public synchronized SQLiteDatabase getWritableDatabase() { * to {@link #getWritableDatabase} may succeed, in which case the read-only * database object will be closed and the read/write object will be returned * in the future. - * + *
*Like {@link #getWritableDatabase}, this method may
* take a long time to return, so you should not call it from the
* application main thread, including from
* {@link android.content.ContentProvider#onCreate ContentProvider.onCreate()}.
*
- * @throws SQLiteException if the database cannot be opened
* @return a database object valid until {@link #getWritableDatabase}
- * or {@link #close} is called.
+ * or {@link #close} is called.
+ * @throws SQLiteException if the database cannot be opened
*/
@Override
public synchronized SQLiteDatabase getReadableDatabase() {
@@ -253,7 +265,9 @@ public synchronized SQLiteDatabase getReadableDatabase() {
try {
return getWritableDatabase();
} catch (SQLiteException e) {
- if (mName == null) throw e; // Can't open a temp database read-only!
+ if (mName == null) {
+ throw e; // Can't open a temp database read-only!
+ }
Log.e(TAG, "Couldn't open " + mName + " for writing (will try read-only):", e);
}
@@ -273,7 +287,9 @@ public synchronized SQLiteDatabase getReadableDatabase() {
return mDatabase;
} finally {
mIsInitializing = false;
- if (db != null && db != mDatabase) db.close();
+ if (db != null && db != mDatabase) {
+ db.close();
+ }
}
}
@@ -282,7 +298,9 @@ public synchronized SQLiteDatabase getReadableDatabase() {
*/
@Override
public synchronized void close() {
- if (mIsInitializing) throw new IllegalStateException("Closed during initialization");
+ if (mIsInitializing) {
+ throw new IllegalStateException("Closed during initialization");
+ }
if (mDatabase != null && mDatabase.isOpen()) {
mDatabase.close();
@@ -304,14 +322,16 @@ public final void onCreate(SQLiteDatabase db) {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- Log.w(TAG, "Upgrading database " + mName + " from version " + oldVersion + " to " + newVersion + "...");
+ Log.w(TAG, "Upgrading database " + mName + " from version " + oldVersion + " to " +
+ newVersion + "...");
ArrayListdatabasename_fromVersionInteger_toVersionInteger
+ * they are equal (though that shouldn't happen), and > 0 if
+ * file0 should be applied after file1.
+ * @throws SQLiteAssetException thrown if the strings are not in the correct upgrade
+ * script format of:
+ * databasename_fromVersionInteger_toVersionInteger
*/
@Override
public int compare(String file0, String file1) {
diff --git a/samples/database-v1/build.gradle b/samples/database-v1/build.gradle
index 708c923..3963842 100644
--- a/samples/database-v1/build.gradle
+++ b/samples/database-v1/build.gradle
@@ -1,19 +1,18 @@
-apply plugin: 'android'
-
-dependencies {
- compile project(':library')
-}
+apply plugin: 'com.android.application'
android {
- buildToolsVersion '19.0.0'
- compileSdkVersion 19
+ compileSdkVersion 22
+ buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
- packageName 'com.example.sqliteassethelper'
- targetSdkVersion 19
+ applicationId 'com.example.sqliteassethelper'
+ targetSdkVersion 22
versionCode 1
versionName '1.0'
}
+ dependencies {
+ compile project(':library')
+ }
}
\ No newline at end of file
diff --git a/samples/database-v13-upgrade/build.gradle b/samples/database-v13-upgrade/build.gradle
index 131d755..918a704 100644
--- a/samples/database-v13-upgrade/build.gradle
+++ b/samples/database-v13-upgrade/build.gradle
@@ -2,34 +2,34 @@ buildscript {
repositories {
mavenCentral()
}
- dependencies {
- classpath 'com.android.tools.build:gradle:0.7.+'
- }
}
-apply plugin: 'android'
+
+apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
- compileSdkVersion 19
- buildToolsVersion "19.0.0"
+ compileSdkVersion 22
+ buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
- targetSdkVersion 19
+ targetSdkVersion 22
versionCode 3
versionName "3.0"
}
+
buildTypes {
release {
- runProguard false
+ minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
-}
-dependencies {
- compile project(':library')
+ dependencies {
+ compile project(':library')
+ }
}
+
diff --git a/samples/database-v2-upgrade/build.gradle b/samples/database-v2-upgrade/build.gradle
index 2be5d87..c5b4081 100644
--- a/samples/database-v2-upgrade/build.gradle
+++ b/samples/database-v2-upgrade/build.gradle
@@ -1,19 +1,18 @@
-apply plugin: 'android'
-
-dependencies {
- compile project(':library')
-}
+apply plugin: 'com.android.application'
android {
- buildToolsVersion '19.0.0'
- compileSdkVersion 19
+ compileSdkVersion 22
+ buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
- packageName 'com.example.sqliteassethelper'
- targetSdkVersion 19
+ applicationId 'com.example.sqliteassethelper'
+ targetSdkVersion 22
versionCode 2
versionName '2.0'
}
+ dependencies {
+ compile project(':library')
+ }
}
\ No newline at end of file