Issue
I have strange problem with SQLcipher build for ARM/x86 device.
When I crypt database with version 2.1.1 and build it with Gradle for ARM and x86 (fat client), it run correctly on ARM device, but on x86 throws error
"No implementation found for native Lnet/sqlcipher/database/SQLiteDatabase;.native_key ([C)V"
When I repeat previous steps with version 2.2.2, it runs on x86, but on ARM it throws previous error.
With version 3.1.0 is result same as version 2.2.2
Can you help me solve it ?
This is content of built apk file (filtered res files):
unzip -l SKG-fat-debug-unaligned.apk | grep -v res/
Archive: SKG-fat-debug-unaligned.apk
Length Date Time Name
-------- ---- ---- ----
113664 05-03-14 22:32 assets/enc.db
2305475 05-03-14 22:32 assets/icudt46l.zip
11937 05-04-14 21:17 assets/postupy.json
7988 05-04-14 21:17 AndroidManifest.xml
228184 05-04-14 21:10 resources.arsc
4348908 05-03-14 22:32 classes.dex
11358 05-04-14 21:17 META-INF/LICENSE.txt
301 05-04-14 21:17 META-INF/NOTICE.txt
38544 05-04-14 21:17 lib/armeabi/libdatabase_sqlcipher.so
21624 05-04-14 21:17 lib/armeabi/libgenerate.so
1176064 05-04-14 21:17 lib/armeabi/libsqlcipher_android.so
402604 05-04-14 21:17 lib/armeabi/libstlport_shared.so
1757156 05-04-14 21:17 lib/x86/libdatabase_sqlcipher.so
17536 05-04-14 21:17 lib/x86/libgenerate.so
3520252 05-04-14 21:17 lib/x86/libsqlcipher_android.so
455740 05-04-14 21:17 lib/x86/libstlport_shared.so
53292 05-04-14 21:17 META-INF/MANIFEST.MF
53321 05-04-14 21:17 META-INF/CERT.SF
776 05-04-14 21:17 META-INF/CERT.RSA
-------- -------
17178672 530 files
This is the error on ARM device:
05-04 21:21:13.377 28356-29048/com.my.app W/dalvikvm﹕ No implementation found for native Lnet/sqlcipher/database/SQLiteDatabase;.native_key ([C)V
05-04 21:21:13.377 28356-29048/com.my.app W/dalvikvm﹕ threadid=12: thread exiting with uncaught exception (group=0x40a98228)
05-04 21:21:13.447 28356-28420/com.my.app I/global﹕ In close() at SocketHttpClientConnection
05-04 21:21:13.587 28356-28420/com.my.app I/global﹕ call createSocket() return a new socket.
05-04 21:21:13.767 28356-29048/com.my.app E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:864)
Caused by: java.lang.UnsatisfiedLinkError: native_key
at net.sqlcipher.database.SQLiteDatabase.native_key(Native Method)
at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1948)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:868)
at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:903)
at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:914)
at com.my.appskg.OtvorDB(skg.java:535)
at com.my.appfsListActivity$asyncOtvorDB.doInBackground(fsListActivity.java:289)
at com.my.appfsListActivity$asyncOtvorDB.doInBackground(fsListActivity.java:80)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:864)
And on x86 device it opens database correctly.
05-04 21:22:38.494 1849-1884/com.my.app D/DeviceID.db﹕ LastError
05-04 21:22:38.874 1849-1849/com.my.app D/com.my.appfsListActivity$asyncOtvorDB﹕ onPostExecute
05-04 21:22:38.890 1849-1849/com.my.app D/fsListActivity﹕ DID.LastError:
05-04 21:22:38.890 1849-1849/com.my.app D/com.my.app.skg﹕ ZoznamCS
05-04 21:22:38.902 1849-1849/com.my.app D/cursor is﹕ net.sqlcipher.CrossProcessCursorWrapper@52aa7f30
This is my code to create encrypted db:
~/Soft/sqlcipher-2.1.1/sqlite3 db.sqlite "ATTACH DATABASE 'enc_v211.db' AS encrypted KEY '$dbkey';SELECT sqlcipher_export('encrypted');DETACH DATABASE encrypted;"
~/Soft/sqlcipher-2.2.1/sqlcipher db.sqlite "ATTACH DATABASE 'enc_v221.db' AS encrypted KEY '$dbkey';SELECT sqlcipher_export('encrypted');DETACH DATABASE encrypted;"
~/Soft/sqlcipher-3.1.0/sqlcipher db.sqlite "ATTACH DATABASE 'enc_v310.db' AS encrypted KEY '$dbkey';SELECT sqlcipher_export('encrypted');DETACH DATABASE encrypted;"
Then I copy encrypted db to assets, and this is my code to open db:
public void OpenDB() {
skg.logD(Thread.currentThread().getStackTrace()[2].getClassName() , Thread.currentThread().getStackTrace()[2].getMethodName());
String dbname = "enc.db";
String dbpath = "/data/data/com.my.app/databases/";
try {
InputStream myInput = context.getAssets().open(dbname);
String outFileName = dbpath + dbname;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
SQLiteDatabase.loadLibs(context);
File databaseFile = context.getDatabasePath(dbpath + dbname);
skg.logD("OtvorDB","getDBpath=" + databaseFile.toString());
DID.context = context;
database = SQLiteDatabase.openOrCreateDatabase(databaseFile, DID.db(), null);
//database = SQLiteDatabase.openDatabase(databaseFile.getAbsolutePath(), DID.db(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
} catch (Exception e) {
e.printStackTrace();
skg.logD("OtvorDB", e.getMessage() + e.toString() + e.getCause());
}
As you can see in code, I have tried with openDatabase, and with openOrCreateDatabase too.
This devices I use for test:
x86 - several devices in Genymotion VM
ARM - 2 real devices, android emulator
App is built without error:
Executing tasks: [:SKG:assembleFatDebug]
Parallel execution with configuration on demand is an incubating feature.
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:SKG:compileFatDebugNdk UP-TO-DATE
:SKG:preBuild
:SKG:preFatDebugBuild
:SKG:checkFatDebugManifest
:SKG:preArmDebugBuild
:SKG:preArmReleaseBuild
:SKG:preArmv7DebugBuild
:SKG:preArmv7ReleaseBuild
:SKG:preFatReleaseBuild
:SKG:preMipsDebugBuild
:SKG:preMipsReleaseBuild
:SKG:preX86DebugBuild
:SKG:preX86ReleaseBuild
:SKG:prepareComAndroidSupportAppcompatV71910Library UP-TO-DATE
:SKG:prepareComGoogleAndroidGmsPlayServices3159Library UP-TO-DATE
:SKG:prepareFatDebugDependencies
:SKG:compileFatDebugAidl UP-TO-DATE
:SKG:compileFatDebugRenderscript UP-TO-DATE
:SKG:generateFatDebugBuildConfig UP-TO-DATE
:SKG:mergeFatDebugAssets UP-TO-DATE
:SKG:generateFatDebugResValues UP-TO-DATE
:SKG:generateFatDebugResources UP-TO-DATE
:SKG:mergeFatDebugResources UP-TO-DATE
:SKG:processFatDebugManifest UP-TO-DATE
:SKG:processFatDebugResources UP-TO-DATE
:SKG:generateFatDebugSources UP-TO-DATE
:SKG:ndkBuild
make: Entering directory `/Users/coudy/git/myapp/SKG/src/main/jni'
[armeabi] Install : libdatabase_sqlcipher.so => libs/armeabi/libdatabase_sqlcipher.so
[armeabi] Install : libgenerate.so => libs/armeabi/libgenerate.so
[armeabi] Install : libsqlcipher_android.so => libs/armeabi/libsqlcipher_android.so
[armeabi] Install : libstlport_shared.so => libs/armeabi/libstlport_shared.so
[x86] Install : libdatabase_sqlcipher.so => libs/x86/libdatabase_sqlcipher.so
[x86] Install : libgenerate.so => libs/x86/libgenerate.so
[x86] Install : libsqlcipher_android.so => libs/x86/libsqlcipher_android.so
[x86] Install : libstlport_shared.so => libs/x86/libstlport_shared.so
make: Leaving directory `/Users/coudy/git/myapp/SKG/src/main/jni'
:SKG:compileFatDebugJava UP-TO-DATE
:SKG:preDexFatDebug UP-TO-DATE
:SKG:dexFatDebug UP-TO-DATE
:SKG:processFatDebugJavaRes UP-TO-DATE
:SKG:validateDebugSigning
:SKG:packageFatDebug
:SKG:assembleFatDebug
BUILD SUCCESSFUL
Total time: 15.848 secs
p.s: I have tried to post this message on SQLCipher user google group, but I don't have permission for it.
Solution
I have replied to your question on the mailing list thread here.
Answered By - Nick Parker
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.