2

I am trying to encrypt database using SQLCipher. I followed http://lomza.totem-soft.com/tutorial-add-sqlcipher-to-your-android-app/ and it was working fine it the app is in debug mode. But whenever i try to build a release version, it crashes. I even tried proguard rules mentioned in every possible site.

Here is my progaurd

-dontwarn javax.annotation.**
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn retrofit2.**
-dontwarn com.roughike.bottombar.**

-keepclassmembers class * implements java.io.Serializable {
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keep public enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keepnames class com.facebook.FacebookActivity
-keepnames class com.facebook.CustomTabActivity

-keep class com.facebook.all.All

-keep public class com.android.vending.billing.IInAppBillingService {
    public static com.android.vending.billing.IInAppBillingService asInterface(android.os.IBinder);
    public android.os.Bundle getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle);
}

# Proguard configuration for Jackson 2.x
-keep class com.fasterxml.jackson.databind.ObjectMapper {
    public <methods>;
    protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
    public ** writeValueAsString(**);
}
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**

# For SQLCipher
-keep class net.sqlcipher.** { *; }
-dontwarn net.sqlcipher.**

And here is the logcat :

E/Database: file is encrypted or is not a database: , while compiling: select count(*) from sqlite_master;
                                             net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: , while compiling: select count(*) from sqlite_master;
                                                 at net.sqlcipher.database.SQLiteCompiledSql.native_compile(Native Method)
                                                 at net.sqlcipher.database.SQLiteCompiledSql.compile(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteCompiledSql.<init>(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteProgram.<init>(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteQuery.<init>(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteDirectCursorDriver.query(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteDatabase.rawQuery(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteDatabase.keyDatabase(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteDatabase.openDatabase(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(Unknown Source)
                                                 at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(Unknown Source)
                                                 at im.gcom.runtime.android.p.c(Unknown Source)
                                                 at im.gcom.runtime.android.p.a(Unknown Source)
                                                 at im.gcom.runtime.af.a(Unknown Source)
                                                 at im.gcom.core.modules.x.a.<init>(Unknown Source)
                                                 at im.gcom.core.modules.q.a(Unknown Source)
                                                 at im.gcom.core.modules.b.a.c(Unknown Source)
                                                 at im.gcom.core.modules.q.z(Unknown Source)
                                                 at im.gcom.core.r.<init>(Unknown Source)
                                                 at im.gcom.core.a.<init>(Unknown Source)
                                                 at im.gcom.sdk.b.b(Unknown Source)
                                                 at im.gcom.sdk.d.run(Unknown Source)
                                                 at android.os.Handler.handleCallback(Handler.java:751)
                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                 at android.os.Looper.loop(Looper.java:154)
                                                 at android.os.HandlerThread.run(HandlerThread.java:61)

I am using compile 'net.zetetic:android-database-sqlcipher:3.5.7@aar'

BST Kaal
  • 2,993
  • 6
  • 34
  • 52
  • What are the circumstances under which you get this stack trace? Are you attempting to open the database for the first time? Are you attempting to open an existing unencrypted database? Are you attempting to open an encrypted database, and if so, are you sure that you are supplying the same encryption key? Also, are you sure that you are calling `loadLibs()` somewhere? – CommonsWare Dec 19 '17 at 11:47
  • Yes i am calling `SQLiteDatabase.loadLibs(this);` in my Application class. and i have checked that the key to encrypt the database is same when i try to access the database. As i have said, if the app is in debug mode, app works perfectly fine. – BST Kaal Dec 19 '17 at 11:53
  • `net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: , while compiling: select count(*) from sqlite_master;` should occur when the key is not the same, but i have checked that its the same one, that's why it works in debug version as well. – BST Kaal Dec 19 '17 at 11:56
  • @BSTKaal I know its beena long time. but did u find any solution to this ? – Karan Sharma May 22 '20 at 03:42
  • @KaranSharma Have you any solution on above issue ? Please help me on it Thanks – Ravindra Kushwaha Jan 08 '21 at 12:57
  • @RavindraKushwaha Nope ! – Karan Sharma Jan 11 '21 at 21:34
  • Luckily yesterday, I got the solution, if you require then will post the answer on the same – Ravindra Kushwaha Jan 12 '21 at 06:10

0 Answers0