Migartion from Eclipse to Android Studio

I migrated my source from eclipse-adt to android studio. Now I have a few errors with net.sqlcipher.database. Do I need some settings or link lib, etc. when migrating to the android studio?

MyLog->
E/libnb: Unable to open /system/lib/arm/libhoudini.so
W/art: Unexpected CPU variant for X86 using defaults: dalvik.vm.isa.x86.features=default
I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sam4s.atom, PID: 5426
java.lang.UnsatisfiedLinkError: dlopen failed: “/data/app/mypackage-1/lib/arm/libstlport_shared.so” has unexpected e_machine: 40
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:142)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:137)
at com.sam4s.util.myDBProvider.onCreate(Sam4sDBProvider.java:5946)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
at android.app.ActivityThread.installProvider(ActivityThread.java:5167)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4762)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4702)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5431)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)

And my app.libs copy android-database-sqlcipher-4.2.0-sources.jar,sqlcipher.jar

And my assets include icudt46l.zip And jniLibs copy libdatabase_sqlcipher.so, libsqlcipher_android.so, libstlport_shared.so

I don’t know why occur error.
can you tell me why occur error? and you tell detail possible? because I beginner.
ah also jar file version is 2.0.5.
I don’t know where download Lates version.
(Sorry I don’t speak English… if you don’t understand , point tell me )
thanks
Also my adb shell data/data/mypackage/lib -> include libstlport_shared.so

Hi @chad

It looks like you may have been using an older version of SQLCipher for Android. You can verify which version you were using by executing the following command using the original library used to create the database:

PRAGMA cipher_version;

If you were using an older version of SQLCipher, I would recommend reviewing the upgrade guidance detailed here:

Oh thanks a lot, I search google And I found traces on you haha
So I fixed that but other error occur
net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master
other people question this problem.
almost you answer check migrate and test suit, alright?
I also have migrate because I’m using a database before
But I don’t know that I’m a beginner
I’m so sorry but can you see an example of migrate(cipher)?
Because guidance is difficult for me So i want example

Finally ->right now, my error point
->
public boolean onCreate() {

    Context context = getContext();
    sContext = context;
    DatabaseHelper dbHelper;
    SQLiteDatabase.loadLibs(context);
    dbHelper = new DatabaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);

    try {
        sDB = dbHelper.getWritableDatabase(DB_PASSWORD);

    } catch (UnsatisfiedLinkError e) {
            Sam4sLog.e(TAG, "UnstatisfiedLinkError!");
            return false;
    }

    return (sDB == null) ? false : true;
}

One more question!!! (i’m so sorry… )

I saw an example of working with migrate elsewhere.
But I tried to follow but failed.
Error Code is package net.zeteic does not exist.
Does not implementation ‘net.zetetic:android-database-sqlcipher:4.2.0@arr’
contain net.zetetic.ZeteticApplication ??

thanks.

Hi @chad

This is an example of performing a PRAGMA cipher_migrate command on an existing database. The ZeteticApplication is a helper class for the test suite.

Thank you so much. I solved my problem.(cipher_migrate success)
But other problem occur. I have 2 DB.class (DBProvider , DBResolver)
First, Work cipher_migrate in DBProvider
Second, DBResolver is the set of query.

Error point is located DBResolver and query is Null PointerException,I think it should also be migrate work.

But I remember that you said you only need to do it once.

thanks.

Hi @1111

Correct, you only need to migrate the file format via pragma cipher_migrate one time per major version change.

hm can you tell me why occur error?? I don’t know because It used to work well in eclipse before
thanks.

It’s mean
Do you have to use SQLiteDatabase.loadLibs(context) when I do query
Do you have any guesses?
(1111 is me)
thanks

Hi @1111

We would need you to provide more details to further troubleshoot any problem you are experiencing.

  • What code is being executed around the site of the error?
  • What SQL is being invoked?
  • Are you operating on an exists SQLCipher database, or a plaintext SQLite database?
  • If it is a SQLCipher database, is it new, or was it migrated from a previous version?
  • What is the stack trace for the error that you receive?
  • Are you able to reproduce the error?

Without this additional information, it would be difficult to speculate as to why you are receiving the error you are.

Hi @developernotes
It’s an Error that occurred when the SQLite version up and
couldn’t use the query that was used before.
I solved whole error.

Lastly,Can you tell how much performance difference is by doing PRAGMA cipher_migrate?
because I used twice (oncreate and database restore).

You’ve been very kind.
Thank you very much.

Last question…
I Wonder when First time installation.(App install)
Android Studio -> App Install -> Error
( java.lang.RuntimeException: Unable to get provider com.sam4s.util.Sam4sDBProvider: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;)
I Know ,It looks like do not migrate
But I did migrate.
Also I press ok and press installed app
not occur error
(Or did I do the wrong point?)
(point is other onCreate()??)

My Code
@Override
public boolean onCreate() {

    Context context = getContext();
    sContext = context;
    SQLiteDatabase.loadLibs(context);
    DatabaseHelper dbHelper;

    try{
            File dbPath = context.getDatabasePath(DATABASE_NAME);
            SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
                @Override
                public void preKey(SQLiteDatabase database) { }
                @Override
                public void postKey(SQLiteDatabase database) {
                    database.rawExecSQL("PRAGMA cipher_migrate;");
                }
        };


        sDB = SQLiteDatabase.openOrCreateDatabase(dbPath,DB_PASSWORD,null,hook);
        sDB.close();

    }catch (Exception e){
        Sam4sLog.e(TAG, ""+e);
    }
    dbHelper = new DatabaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);

    try {
        sDB = dbHelper.getWritableDatabase(DB_PASSWORD);

    } catch (UnsatisfiedLinkError e) {
            Sam4sLog.e(TAG, "UnstatisfiedLinkError!");
            return false;
    }

    return (sDB == null) ? false : true;
}

thanks…

Hi @chad

It is difficult to say what caused the specific error you are seeing. If the database file did not exist previously, you should not perform a cipher_migrate command against it. You should also check the result code of the cipher_migrate command. An example of this can be found here. Are you able to reproduce the behavior?

In terms of the performance of running cipher_migrate, you should only perform the operation once per database file format upgrade. That is, if you have a database which was created using a different major version of SQLCipher than you are currently using, you should perform the migrate command once. There are a couple of approaches for this, however a common approach is the attempt to open the database with the provided password without a hook. If it opens, no migration is necessary. If it fails, you can try opening the connection using the same password, but provide a hook to perform the migration. If that also fails, the user may have entered an invalid password.

Hi @developernotes
thanks developer.
I fix it. thanks. Thank you for your feedback.
Finally, I have one question.
when I finish migrate, does myDB save as a new version(update version)?

Hi @chad

The call to pragma cipher_migrate does not modify the pragma user_version value you have stored, that would remain the same. You would need to manage the user_version value as you perform any schema migration separately.