SQLcipher (different versions) works on one platform , but crash on other platform

599 views
Skip to first unread message

Radoslav Chovan

unread,
May 5, 2014, 2:26:04 AM5/5/14
to sqlc...@googlegroups.com

Hello,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 - 2x real devices, 2x 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: post to stackoverflow.com, because I didn't have permission to post it here. link: http://stackoverflow.com/questions/23460841/sqlcipher-different-versions-works-on-one-platform-but-crash-on-other-platfo

Nick Parker

unread,
May 5, 2014, 9:30:14 AM5/5/14
to sqlc...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Radoslav,

It sounds as if the there may be an issue with packaging the proper
native libraries using Gradle. Could you try the SQLCipher for
Android test suite [1] using your current devices? Are you able to
run them properly on each platform? It is setup with both ARM and x86
native libraries, however uses a maven instead of Gradle.


[1] https://github.com/sqlcipher/sqlcipher-android-tests

On 5/5/14, 1:26 AM, Radoslav Chovan wrote:
> Hello,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:_
> _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 - 2x real devices, 2x android emulator
>
> _App is built without error:_
> --
>
> --- You received this message because you are subscribed to the
> Google Groups "SQLCipher Users" group. To unsubscribe from this
> group and stop receiving emails from it, send an email to
> sqlcipher+...@googlegroups.com
> <mailto:sqlcipher+...@googlegroups.com>. For more options,
> visit https://groups.google.com/d/optout.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJTZ5JmAAoJEC+HMEgI1AzswLAQAIwj/9dEDewkrETgxEzqsROm
Gyr7wPNNXll1sLBs2oX87mxWJKznuLL/WX/VHEFNMYqE63P0U2eZcaCs2vP78lbt
1UJxEm1BdPbxDZPpVLcwQc7B1j8YWtWGc+ce5SyitWZjbnp2bjpNrw/ShF931Hhf
EjA/qEyoWhJaXuKwOPybzE1eNAWG9+ZmPvHHwvbgU3Lr5D3OCCKFHFwBcb0JMuGU
29zbF0SzF1QPdR1aSR4LR3R0z3cUFJBhSnRz4LU2+RnLymnALeGEHJn1bZTURAFp
PoKZDQtdVzwRf7ibGlBjv9jAyH8QrEEk+RWzv5Ez/RboPC+GTnLeLQKu4horjaQr
rxK0edff0gz7ojqKIUHZv0EHVPDGOyIMeg4Y4QVUGWizUBUEZPQxSO1OHq8fW1At
djGTCRMn1wwyZqpRQlwWToEKpr6x9wfqCuOwej8Z86zwhHfztKDZO6wGabbuirx+
+BgfcoTvxIEdrlc6ll9gNDjbysKUI0yr3wbypfymc1ThtOvta7fvXmFALyKXuU41
ktEpbThjNVUFb66Pz0rqmf4TL0g6U2bWFmKUoziLjralMvb2L7qDnZ71mp68Izds
RmOGfoGZnSrHRYb1PxKhc3hbS/s0+xFWoDnWMNJUSgeNXbLg9GAN2snjaZ9Bae8f
NehPiIU6PUiRP53odDuT
=wW57
-----END PGP SIGNATURE-----

Radoslav Chovan

unread,
May 5, 2014, 1:59:32 PM5/5/14
to sqlc...@googlegroups.com
Hello,
I just used your libraries for x86 and armeabi, with sqlcipher.jar and it is working on both platforms.
Thank you, but still I have question, why it does not work for me ? I have downloaded libs from github,


Dňa pondelok, 5. mája 2014 8:26:04 UTC+2 Radoslav Chovan napísal(-a):
...

Nick Parker

unread,
May 5, 2014, 5:39:19 PM5/5/14
to sqlc...@googlegroups.com
Hello Radoslav,

We distribute the SQLCipher for Android libraries via our site [1]. I
do not know where on Github you have previously sourced SQLCipher
libraries. We are glad to hear it is working for you now.

[1] http://sqlcipher.net/open-source

On 5/5/14, 12:59 PM, Radoslav Chovan wrote:
> Hello,
> I just used your libraries for x86 and armeabi, with sqlcipher.jar and
> it is working on both platforms.
> Thank you, but still I have question, why it does not work for me ? I
> have downloaded libs from github,
>
>
> Dňa pondelok, 5. mája 2014 8:26:04 UTC+2 Radoslav Chovan napísal(-a):
>
> Hello,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):_
> _This is the error on ARM device:_
> _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);|
>
> ...
>
signature.asc
Reply all
Reply to author
Forward
0 new messages