Hi,
I am using SQLCipher in my android app project (in Android Studio 2.0 preview) by adding following line in dependencies
-
compile 'net.zetetic:android-database-sqlcipher:3.3.1-2@aar'
I am a medical doctor, and have very restricted information about programming. After going through many tutorials available on net / stackoverflow questions, I decided to work with NDK to secure password string of my pre-populated database encrypted with SQLCipher. (I know, this might be a childish way to secure string for you people, but this is the only thing, I could learn to protect my string which has to be on device for offline use, given my background is purely Medical / Non-programming.)
Anyways, using NDK, I created settings-jni.c
file in my jni
folder, which has following code -
#include <jni.h>
JNIEXPORT jstring JNICALL
Java_in_medicalguru_database_DBHelper_getDBPwd(JNIEnv *env, jobject instance) {
return (*env)->NewStringUTF(env, "my_password_string");
}
In my DBHelper.java
file I am getting my password as follows -
public String DB_PASSWORD = getDBPwd();
static {
System.loadLibrary("settings-jni");
}
public native String getDBPwd();
My app compiles fine (for the record, I am making universal app for all architecture, I am yet to learn to make app targeting specific architecture) and runs perfect on many devices I tested, e.g. Samsung Galaxy Grand, OnePlus One, Moto G2 etc. I also tested it on Emulator using “Visual Studio Emulator for Android”, because it works faster on my Windows 10 laptop.
Now comes the actual problem part. Recently, some of my user reported, that my app is continuously crashing soon after starting. On investigation, I found that these users are using x64 architecture mobiles. One of user also said that, earlier version of my app (which did not use NDK to encrypt password string), was working fine for him.
Here is the error log I received in my Google Play Developer Console -
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/in.medicalguru-1/base.apk"],nativeLibraryDirectories=[/data/app/in.medicalguru-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libstlport_shared.so"
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:988)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(Unknown Source)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(Unknown Source)
at in.medicalguru.MainActivity.a(Unknown Source)
at in.medicalguru.MainActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
So I unzipped both versions of my app, and checked the list of libraries. I am attaching the screenshot of library structure of my final (unzipped) app, which uses NDK -
In this I noticed the difference that, because of me using the NDK, 4 folders are created extra - arm64-v8a
, mips
, mips64
and x86_64
. These folders do NOT contain SQLCipher’s .so
files. So as per my knowledge (I am saying again that I may be very wrong, but please correct me, if I am) this might be causing the app to crash on x64
mobiles,
If I am correct in diagnosing the cause of app crash, how can I correct it? There are two possible scenarios I could think of (but don’t know how to apply them) -
- Either include SQLCipher’s
.so
files for the mentioned 4 folders - Or to restrict making
.so
files from mysettings-jni.c
file, for the mentioned 4 architectures.
I am completely clueless here, and stuck since days,
Any help would be appreciated.
[P.S. - I am really sorry for the long post, but I think, it was necessary to explain my problem.]
Thanks.
Regards,
Dr, Atul Tiwari