Crash app when install and open signed apk but no problem when debug

Hi
I converted my sqlite database into encrypted database by this method :

public static void encrypt(Context ctxt, String dbName,
                         String passphrase) throws IOException {
File originalFile=ctxt.getDatabasePath(dbName);

if (originalFile.exists()) {
  File newFile=
      File.createTempFile("sqlcipherutils", "tmp",
                          ctxt.getCacheDir());
  SQLiteDatabase db=
      SQLiteDatabase.openDatabase(originalFile.getAbsolutePath(),
                                  "", null,
                                  SQLiteDatabase.OPEN_READWRITE);

  db.rawExecSQL(String.format("ATTACH DATABASE '%s' AS encrypted KEY '%s';",
                              newFile.getAbsolutePath(), passphrase));
  db.rawExecSQL("SELECT sqlcipher_export('encrypted')");
  db.rawExecSQL("DETACH DATABASE encrypted;");

  int version=db.getVersion();

  db.close();

  db=
      SQLiteDatabase.openDatabase(newFile.getAbsolutePath(),
                                  passphrase, null,
                                  SQLiteDatabase.OPEN_READWRITE);
  db.setVersion(version);
  db.close();

  originalFile.delete();
  newFile.renameTo(originalFile);
}
}

then In Android studio I replaced the database file with the previous file in the assets folder and added this line below to the gradle .

compile 'net.zetetic:android-database-sqlcipher:3.5.2'

I also in the sqliteopenhelper class replaced all of the imports which are starting with “android.database.sqlite” with “net.sqlcipher.database”.

These are all of my imports :

import android.content.ContentValues;
import android.content.Context;
import net.sqlcipher.Cursor;
import net.sqlcipher.SQLException;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteException;
import net.sqlcipher.database.SQLiteOpenHelper;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

In addition, in the “sqliteopenhelper” class, I replaced codes below with the previous codes:

this.getReadableDatabase("pass");

and

 myDataBase =   
 SQLiteDatabase.openDatabase(myPath,"pass",null,SQLiteDatabase.OPEN_READWRITE);

Now, when I’m going to run the app from Android studio it installs and runs with no errors and works perfeclty ; but when I take " build apk" or " generate signed apk" and then install the apk file it installs but whenever I open the application it crashes and all the error messages below will show in the “logcat”:

Caused by: java.lang.NoClassDefFoundError: net/sqlcipher/CursorWindow
Caused by: java.lang.NoClassDefFoundError: net/sqlcipher/database/SQLiteStatement
Caused by: java.lang.NoClassDefFoundError: net/sqlcipher/database/SQLiteProgram
Caused by: java.lang.NoClassDefFoundError: net/sqlcipher/database/SQLiteQuery
Caused by: java.lang.NoClassDefFoundError: net/sqlcipher/database/SQLiteCompiledSql
Caused by: java.lang.NoSuchFieldError: no field with name='mNativeHandle' signature='I' in class   
Lnet/sqlcipher/database/SQLiteDatabase

For solving this problems I did this steps below but it got no effects and the problem still exists

1- I added lines below to “proguard_rules.pro”

-keep
class net.sqlcipher.** {*;}

-keep
class net.sqlcipher.database.** {*;}

2- I changed " gradle " address to the shown address below :

compile 'net.zetetic:android-database-sqlcipher:3.5.3@aar'

3- I added all of the jar library files from into the project.

please tell me where is wrong.thank a lot.

Hi @sajad471

It sounds like a ProGuard related issue. You might consider trying using the sample ProGuard file provided here.

thank you so much @developernotes

Thanks … solve my issue