Android Question SQLITE on Marshmallow

Rusty

Well-Known Member
Licensed User
Longtime User
Is there a new SQLite version that is able to run on Marshmallow?
My exact version of code that runs on ICS to KitKat is blowing up in the first SQLite IO.
java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/talkingsurvey.b4a.survey-2/lib/arm/libstlport_shared.so: has text relocations
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 anyhwheresoftware.b4a.objects.sqlcipher.SQLCipher.Initialize(SQLCipher.java:50)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:747)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.objects.SaxParser$MyHandler.endElement(SaxParser.java:121)
at org.apache.harmony.xml.ExpatParser.endElement(ExpatParser.java:156)
at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:513)
at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:316)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
at anywheresoftware.b4a.objects.SaxParser.parse(SaxParser.java:80)
at anywheresoftware.b4a.objects.SaxParser.Parse(SaxParser.java:73)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:267)
at talkingsurvey.b4a.survey.main._loadorganization(main.java:2314)
at talkingsurvey.b4a.survey.main._activity_create(main.java:1485)

I'm using:
SQL version 1.30
SQLCipher version 1.20
icudt46l.zip
 

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks,
I have attempted to follow those instructions but it is still failing.
B4X:
Try
                    Main.SQLSurvey.initialize(Main.SDCard.data, Main.DBSurvey, False, Main.SqliteKey, File.DirAssets ) 'use the encrypted database
                    Dim C As Cursor = Main.SQLSurvey.ExecQuery ("PRAGMA cipher_migrate")  'convert 1.2 to 1.3
                Catch
                    Main.SQLSurvey.initialize(Main.SDCard.data, Main.DBSurvey, False, "", File.DirAssets )  'in case it's not encrypted
                End Try
                Try
                    Dim C As Cursor = Main.SQLSurvey.ExecQuery("PRAGMA journal_mode=OFF") 'kill any journalling
                    Retcd = True
                Catch
                    Log("Couldn't set Pragma " & Main.SQLSurvey)
                End Try
                Try
                    C.Close   
                Catch
                    Log(LastException)
                End Try
(lots of try catches:))

JAR versions:
SQL v 1.30
SQLCipher v1.30

Results: net.sqlcipher.database.SQLiteException: error code 14: Could not open database
FN Opening Sqlresponse /storage/emulated/0/survey/packages/Customer_Data/data Customer_Data~78_24_af_26_82_fa~20160619.db3<
Trying to load lib /data/app-lib/talkingsurvey.b4a.survey-1/libstlport_shared.so 0x43c4f000
Shared lib '/data/app-lib/talkingsurvey.b4a.survey-1/libstlport_shared.so' already loaded in same CL 0x43c4f000
Trying to load lib /data/app-lib/talkingsurvey.b4a.survey-1/libsqlcipher_android.so 0x43c4f000
Shared lib '/data/app-lib/talkingsurvey.b4a.survey-1/libsqlcipher_android.so' already loaded in same CL 0x43c4f000
Trying to load lib /data/app-lib/talkingsurvey.b4a.survey-1/libdatabase_sqlcipher.so 0x43c4f000
Shared lib '/data/app-lib/talkingsurvey.b4a.survey-1/libdatabase_sqlcipher.so' already loaded in same CL 0x43c4f000
sqlite returned: error code = 14, msg = cannot open file at line 34892 of [2ef4f3a5b1]
sqlite returned: error code = 14, msg = os_unix.c:34892: (2) open(/storage/emulated/0/survey/packages/Customer_Data/data/Customer_Data~78_24_af_26_82_fa~20160619.db3) -
sqlite3_open_v2("/storage/emulated/0/survey/packages/Customer_Data/data/Customer_Data~78_24_af_26_82_fa~20160619.db3", &handle, 2, NULL) failed
Trying to load lib /data/app-lib/talkingsurvey.b4a.survey-1/libstlport_shared.so 0x43c4f000
Shared lib '/data/app-lib/talkingsurvey.b4a.survey-1/libstlport_shared.so' already loaded in same CL 0x43c4f000
Trying to load lib /data/app-lib/talkingsurvey.b4a.survey-1/libsqlcipher_android.so 0x43c4f000
Shared lib '/data/app-lib/talkingsurvey.b4a.survey-1/libsqlcipher_android.so' already loaded in same CL 0x43c4f000
Trying to load lib /data/app-lib/talkingsurvey.b4a.survey-1/libdatabase_sqlcipher.so 0x43c4f000
Shared lib '/data/app-lib/talkingsurvey.b4a.survey-1/libdatabase_sqlcipher.so' already loaded in same CL 0x43c4f000
sqlite returned: error code = 14, msg = cannot open file at line 34892 of [2ef4f3a5b1]
sqlite returned: error code = 14, msg = os_unix.c:34892: (2) open(/storage/emulated/0/survey/packages/Customer_Data/data/Customer_Data~78_24_af_26_82_fa~20160619.db3) -
sqlite3_open_v2("/storage/emulated/0/survey/packages/Customer_Data/data/Customer_Data~78_24_af_26_82_fa~20160619.db3", &handle, 2, NULL) failed
Any insight will be appreciated.
Thanks
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
NEW STATUS: I failed to put #DebuggerForceStandardAssets: True in the attributes, after adding this, it is now running the Klaus SimpleSQLite1, converted.
My main app, however is still failing...

I can compile and successfully run Klaus' SimpleSQLite1 example to Cipher here
When I convert it to SQLCipher, it crashes.
B4X:
        If File.Exists(File.DirInternal, "persons.db") = False Then
            'if not, initialize it
            'Main.SQLSurvey.initialize(Main.SDCard.data, Main.DBSurvey, False, Main.SqliteKey, File.DirAssets )
            SQL1.Initialize(File.DirInternal, "persons.db", True, "abc", File.DirAssets)
            'and create it
            CreateDataBase
        Else
            'if yes, initialize it
            SQL1.Initialize(File.DirInternal, "persons.db", False, "abc", File.DirAssets)
        End If
it says :
java.lang.RuntimeException: java.io.FileNotFoundException: icudt46l.zip

Error occurred on line: 73 (Main)
java.lang.RuntimeException: java.io.FileNotFoundException: icudt46l.zip
at net.sqlcipher.database.SQLiteDatabase.loadICUData(SQLiteDatabase.java:150)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:182)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:169)
at anyhwheresoftware.b4a.objects.sqlcipher.SQLCipher.Initialize(SQLCipher.java:50)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:747)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.sqlitelight1.main.afterFirstLayout(main.java:102)
at b4a.sqlitelight1.main.access$000(main.java:17)
at b4a.sqlitelight1.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)

The file IS there though.
 
Last edited:
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
...OK, I got it working in my app and the databases are all migrated.
Last question, once the databases are migrated, how can we know that the database has been migrated so we can discontinue "migrating" each time?
thanks,
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Hi Erel,
Thanks for the advice.
I found a user field available that might work without using a table (version).
Will the following code be as efficient?

B4X:
'checks database version and migrates if necessary
'SQL1 must already be initialized
Sub MigrateSQLite(SQL1 As SQLCipher, CurVer As Int)
    Dim thisVer As Int = SQL1.ExecQuerySingleResult ("PRAGMA user_version")    'get the version
    Dim C As Cursor
    If thisVer < CurVer Then
        C = SQL1.ExecQuery ("PRAGMA cipher_migrate")                     'migrate the database to the new version
        SQL1.ExecNonQuery("PRAGMA user_version = " & CurVer)        'set the new version
    End If
    Try
        C = SQL1.ExecQuery("PRAGMA journal_mode=OFF")
    Catch
        Log("Couldn't set Pragma " & SQL1)
    End Try
    C.Close
End Sub
 
Upvote 0
Top