sqlcipher / android-database-sqlcipher

Android SQLite API based on SQLCipher
https://www.zetetic.net/sqlcipher/sqlcipher-for-android/
Other
2.72k stars 564 forks source link

Updation from android-database-sqlcipher to sqlcipher-android #643

Open ashishgingercube opened 1 month ago

ashishgingercube commented 1 month ago

Hi, my application has been using android-database-sqlcipher for quite some years now. Today I got the following message from playstore.

net.zetetic:android-database-sqlcipher has reported android-database-sqlcipher:3.5.9 as outdated. You may not be able to release future versions of your app with this SDK version to production or open testing.

so I replaced implementation ‘net.zetetic:android-database-sqlcipher:3.5.9@aar’ with implementation ‘net.zetetic:sqlcipher-android:4.5.5@aar’

But on doing that I am getting this issue.

Task :maxRVU:mergeMaxrvuDebugNativeLibs FAILED Execution failed for task ‘:maxRVU:mergeMaxrvuDebugNativeLibs’. A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction 2 files found with path ‘lib/arm64-v8a/libsqlcipher.so’ from inputs:

Can you help me with what I can do to fix this issues?

Thank you.

developernotes commented 1 month ago

Hi @ashishgingercube,

You have to remove the android-database-sqlcipher reference from Gradle. We have migration instruction here ^1.

ashishgingercube commented 1 month ago

Hi, I have removed implementation 'net.zetetic:android-database-sqlcipher:3.5.9@aar'

and added

implementation 'net.zetetic:sqlcipher-android:4.5.5@aar' implementation 'androidx.sqlite:sqlite:2.2.0'

packagingOptions { exclude 'lib/arm64-v8a/libsqlcipher.so' exclude 'lib/armeabi-v7a/libsqlcipher.so' exclude 'lib/x86/libsqlcipher.so' exclude 'lib/x86_64/libsqlcipher.so' }

and in my activity I have changed this

SQLiteDatabase.loadLibs(_mContext);

to

SQLiteDatabase.loadLibs(_mContext, libraries -> { for (String library : libraries) { ReLinker.loadLibrary(_mContext, library); } });

But now I am getting this issue

java.lang.UnsatisfiedLinkError: dlopen failed: library "libsqlcipher.so" not found

Can you please help me with this issue?

Thank you.

developernotes commented 1 month ago

Why are you excluding the native libsqlcipher.so? The native library is included within the SQLCipher for Android AAR and is needed.

DinShopper commented 1 month ago

Hello fellows, I received the same mesage from the playstore. "net.zetetic:android-database-sqlcipher has reported android-database-sqlcipher:3.5.9 as outdated. You may not be able to release future versions of your app with this SDK version to production or open testing." does that mean i have to update it to version starting with 4.x or migrate to the newer "net.zetetic:sqlcipher-android" library. I know the latter would be better option, but it caught me off guard and full migration to different API would take time and testing. So can i just update it to version 4.x and migrate just the db's?

ashishgingercube commented 1 month ago

Task :maxRVU:mergeMaxrvuDebugNativeLibs FAILED Execution failed for task ‘:maxRVU:mergeMaxrvuDebugNativeLibs’. A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction 2 files found with path ‘lib/arm64-v8a/libsqlcipher.so’ from inputs:

  • /Users/ashish/.gradle/caches/transforms-3/47cad2ebd25762db6d4f72d65143456b/transformed/jetified-sqlcipher-android-4.5.5/jni/arm64-v8a/libsqlcipher.so
  • /Users/ashish/.gradle/caches/transforms-3/ff8ddd5b58a3b5727c6ff94414d581dd/transformed/jetified-android-database-sqlcipher-3.5.9/jni/arm64-v8a/libsqlcipher.so

I excluded the libsqlcipher.so because I was getting this error

Task :maxRVU:mergeMaxrvuDebugNativeLibs FAILED Execution failed for task ‘:maxRVU:mergeMaxrvuDebugNativeLibs’. A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction 2 files found with path ‘lib/arm64-v8a/libsqlcipher.so’ from inputs:

/Users/ashish/.gradle/caches/transforms-3/47cad2ebd25762db6d4f72d65143456b/transformed/jetified-sqlcipher-android-4.5.5/jni/arm64-v8a/libsqlcipher.so /Users/ashish/.gradle/caches/transforms-3/ff8ddd5b58a3b5727c6ff94414d581dd/transformed/jetified-android-database-sqlcipher-3.5.9/jni/arm64-v8a/libsqlcipher.so

Can you help me with this issue? And how long will it be until I can no longer use the current version I am using?

Thank you.

developernotes commented 1 month ago

Hello @DinShopper,

The android-database-sqlcipher library was officially deprecated last year ^1. You are welcome to migrate to the 4.x series of that library, however, please note that Community updates are no longer being made. The long-term replacement library is sqlcipher-android ^2 and is kept up-to-date with public SQLCipher core releases. We have a migration guide available here ^3. If you have a Commercial need for android-database-sqlcipher, please reach out ^4.

DinShopper commented 1 month ago

Hello @developernotes,

Thank you very much for the fast response. I am planning to update to the sqlcipher-android, but for the time being a way to avoid the Google Play Store message is a priority for me. Is there a page (link) where i can see which versions of the old library (android-database-sqlcipher) are currently outdated for the Google Play Store. Are only the 3.x versions marked as outdated, or are the 4.x versions also considered outdated?

developernotes commented 1 month ago

@DinShopper,

android-database-sqlcipher 4.2.0 and up to 4.5.4 (the last Community edition release of android-database-sqlcipher) are not marked as outdated currently. If you are migrating from version 3.x to 4.x of SQLCipher (regardless of the library itself), please also review the Upgrading to SQLCipher 4 guidance here ^1.

developernotes commented 1 month ago

Hi @ashishgingercube,

Please try cleaning your Gradle cache if you are still getting a merge native libs error if you've already settled on either only android-database-sqlcipher or sqlcipher-android within your application. Also, please remove the exclude lines within your packagingOptions.

asifsaifi92 commented 1 month ago

Hi @developernotes ,

I am getting this error and app is getting crashed.

java.lang.UnsatisfiedLinkError: No implementation found for void net.sqlcipher.database.SQLiteDatabase.dbopen(java.lang.String, int) (tried Java_net_sqlcipher_database_SQLiteDatabase_dbopen and Java_net_sqlcipher_database_SQLiteDatabase_dbopen__Ljava_lang_String_2I)

developernotes commented 1 month ago

Hi @asifsaifi92,

I am getting this error and app is getting crashed. java.lang.UnsatisfiedLinkError: No implementation found for void net.sqlcipher.database.SQLiteDatabase.dbopen(java.lang.String, int) (tried Java_net_sqlcipher_database_SQLiteDatabase_dbopen and Java_net_sqlcipher_database_SQLiteDatabase_dbopen__Ljava_lang_String_2I)

Unfortunately, this is not enough information to diagnose the issue you are experiencing. Below are some questions that would help us better understand your situation:

If your issue is not related to the initial posting, please consider posting a new separate issue.

ashishgingercube commented 1 month ago

Hi @ashishgingercube,

Please try cleaning your Gradle cache if you are still getting a merge native libs error if you've already settled on either only android-database-sqlcipher or sqlcipher-android within your application. Also, please remove the exclude lines within your packagingOptions.

Hi, thanks for the reply. So I went back & deleted the cache folder in my .gradle folder. Invalidated the cache in my android studio. Also removed the exclude lines as you instructed. Then in my gradle file I replaced 'implementation 'net.zetetic:android-database-sqlcipher:3.5.9@aar'' with 'implementation 'net.zetetic:sqlcipher-android:4.5.5@aar''. But still I'm getting this error -

2 files found with path 'lib/arm64-v8a/libsqlcipher.so' from inputs:

developernotes commented 1 month ago

Hi @ashishgingercube,

You will need to review your dependencies, both direct and transitive as it appears you are pulling in both android-database-sqlcipher and sqlcipher-android, both of which bundle native libraries.

ashishgingercube commented 1 month ago

Hi @ashishgingercube,

You will need to review your dependencies, both direct and transitive as it appears you are pulling in both android-database-sqlcipher and sqlcipher-android, both of which bundle native libraries.

Hi, thanks for the reply. I checked my dependencies & found that this dependency creates android-database-sqlcipher folder

implementation "com.commonsware.cwac:saferoom.x:0.5.1"

But I can't remove this because it is connected to a lot of places in my application. Can you suggest a way out for me? Thank you.

ashishgingercube commented 1 month ago

Hi @ashishgingercube,

You will need to review your dependencies, both direct and transitive as it appears you are pulling in both android-database-sqlcipher and sqlcipher-android, both of which bundle native libraries.

Hi, also can you let me know an approximate time till when I can use android-database-sqlcipher version 4.2.0+ ? Since removing com.commonsware.cwac:saferoom.x:0.5.1 on short notice will require a lot of work because my app has live users. Thanks in advance.

developernotes commented 1 month ago

Hello @ashishgingercube - we can't provide an exact time for how long you can use 4.2.0. As mentioned earlier, the android-database-sqlcipher package is deprecated. You are free to keep using it in your application, though you will not see any updates for it in the future. At some point we may choose to de-list it, but that will probably not be in the immediate future. For now it is safe to use it to get your application updated and released, but you should consider it a priority to move to sqlcipher-android in a timely manner.

ashishgingercube commented 1 month ago

Hello @ashishgingercube - we can't provide an exact time for how long you can use 4.2.0. As mentioned earlier, the android-database-sqlcipher package is deprecated. You are free to keep using it in your application, though you will not see any updates for it in the future. At some point we may choose to de-list it, but that will probably not be in the immediate future. For now it is safe to use it to get your application updated and released, but you should consider it a priority to move to sqlcipher-android in a timely manner.

Hi, thanks for the update. Much appreciated.

DinShopper commented 2 weeks ago

Hello, @developernotes

I have a question: Is there a specific rationale for validating the result of executing 'PRAGMA cipher_migrate;' to be (0), or can I rely on the library itself to throw exceptions afterwards to detect that migration failed?

developernotes commented 2 weeks ago

Hi @DinShopper,

No, you should not expect an exception to be raised when executing PRAGMA cipher_migrate; you should check the numeric result code for success.

ashishgingercube commented 1 week ago

Hi @DinShopper, so when I upgraded to "net.zetetic:android-database-sqlcipher:4.2.0@aar" & "com.commonsware.cwac:saferoom.x:1.0.0" & ran the application I got this error "Caused by: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;". But when I uninstall the application & re-run it again then it works. This is my code.

mInstance = Room.databaseBuilder(context, MaxRVURewampDatabase.class, "MaxRVU-db.sql") .openHelperFactory(factory) .allowMainThreadQueries() .addMigrations(MIGRATION_1_2) .build();

Can you help me in identifying what could be the issue here? Thanks in advance.

DinShopper commented 6 days ago

Hi, @developernotes

I see, i though that i can rely on the exception that is thrown afterwards, because after the hook tries to migrate the database - if it's ok the opened connection can be used and if the hook fails it throws an exception that like this "net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;"

DinShopper commented 6 days ago

Hi, @ashishgingercube

After you uninstall the application and install it again the database is newly created with the SQLCipher 4 settings and that's why it's ok and working. I suspect in your case that you are not migrating the already created databases from the previous version of your application.

developernotes commented 6 days ago

Hi @DinShopper,

I see, i though that i can rely on the exception that is thrown afterwards, because after the hook tries to migrate the database - if it's ok the opened connection can be used and if the hook fails it throws an exception that like this "net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;"

Yes, that is fine.