Android Question SQLCipher 1.2 and SQLCipher 1.3 in same app

Rusty

Well-Known Member
Licensed User
Longtime User
I have many pre-Android 6 tablets and cellphones out in the field.
I've deployed several 6+ tablets and phones.
I need to support all of them (hopefully) with the same application version.
Can one:
  1. Determine the OS version
  2. Based upon the version,
  3. Open a V1.2 Cipher database, if old OS version
  4. Open a V1.3 Cipher database, if new OS version
Any ideas are appreciated.
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks Erel,
Are there conditional compile options such that when compiling, one could include V1.2 or V1.3 depending compilation selection?
Or does one have to maintain duplicate code?
Rusty
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The difference between the libraries is the referenced sqlcipher_native.jar.

You can edit the XML file of both libraries and remove the reference to sqlcipher_native (look for DepensOn).

This will allow you to write this code:
B4X:
#If UseSQLCipher12
 #AdditionalJar: sqlcipher_native12
#Else
 #AdditionalJar: sqlcipher_native
#End If
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
This is great Erel.
How does one set the UseSQLCipher12 "variable"?
Rusty
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
I'm finally where I can try this.
I've added the #If UseSQLCipher12...
#Region Module Attributes
#FullScreen: True
#IncludeTitle: False
#ApplicationLabel: abc
#VersionCode: 8
#VersionName: 8.13 2017-01-01
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#BridgeLogger: True
#LibraryAuthor: Copyright abc Inc.2009-2016
#IgnoreWarnings: 15
#AdditionalRes: ..\resources
#AdditionalJar: com.google.android.gms:play-services-location
#if UseSQLCipher12
#AdditionalJar: sqlcipher v1.2
#Else
#AdditionalJar: sqlcipher v1.3
#End If
#ExcludeClasses: .games, .drive, .ads, .wearable, .measurement, .cast, .auth, .nearby
#ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .vision, .gcm
#End Region
I've added the UseSQLCipher12 in the Ctrl-B window; Configuration: Default; Configuration Name: Default Packagename: mine; Contitional Symbols: UseSQLCipher12
To get it to even begin to compile, I have to include the SQLCipher Lib in the Libraries window...Is this correct? I'm using Debug, if that matters.
The compiler abends with:
B4A version: 6.80
Parsing code. (1.64s)
Compiling code. (2.91s)
Compiling layouts code. (0.09s)
Organizing libraries. (1.22s)
Generating R file. (0.21s)
Compiling debugger engine code. (8.39s)
Compiling generated Java code. (8.85s)
Convert byte code - optimized dex. Error
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lanyhwheresoftware/b4a/objects/sqlcipher/SQLCipher;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
at com.android.dx.command.dexer.Main.processClass(Main.java:615)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:570)
at com.android.dx.command.dexer.Main.access$2(Main.java:546)
at com.android.dx.command.dexer.Main$2.processFileBytes(Main.java:514)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:537)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:449)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:236)
at com.android.dx.command.dexer.Main.run(Main.java:206)
at com.android.dx.command.dexer.Main.main(Main.java:179)
at com.android.dx.command.Main.main(Main.java:103)
1 error; aborting
Can you advise what I am doing incorrectly?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Can you advise what I am doing incorrectly?
I guess you did not follow #4 correctly

This looks wrong
B4X:
#if UseSQLCipher12
#AdditionalJar: sqlcipher v1.2
#Else
#AdditionalJar: sqlcipher v1.3
#End If

This is how it should look like

B4X:
#If UseSQLCipher12
#AdditionalJar: sqlcipher_native12
#Else
#AdditionalJar: sqlcipher_native
#End If

Note that you need to rename one of the native jars.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
To be more precise:

From sqlcipher V1.2
Rename sqlcipher_native.jar to sqlcipher_native12.jar
Put it in additional libs folder

From V1.3
Put the sqlcipher_native.jar into your additional libs folder

Note that you need to REMOVE the dependson line as described in #4 (from BOTH libs)

In the Library tab ONLY mark the newest (V1.3)
 
Last edited:
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks Don,
I still unclear. My fault, when we migrated from 1.2 to 1.3, I renamed the sqlcipher.jar to sqlcipher v1.2.jar and the new one to SqlCipher v1.3.jar along with the associated XML files. I also renamed the sqlcipher_native jars similarly.
There are two files (I think) that are germane, SQLCipher and sqlcipher_native for EACH version.
How do I store two copies of SQLCipher in the same folder on my development computer?
I can delete any extras (see below) and properly name the others, but I don't know what to do with the V1.2 and V1.3 SQLcipher libs


upload_2017-3-30_5-1-24.png


When I compile with the above scenario, it compiles but when it starts to run as soon as I open my first V1.3 file, I get:
V1.3 file:
Fatal signal 6 (SIGABRT) at 0x00002e2c (code=-6), thread 11820 (rvey.b4a.survey)
V1.2 file
Fatal signal 6 (SIGABRT) at 0x0000301d (code=-6), thread 12317 (rvey.b4a.survey)

Your advice?
Thanks,
Rusty
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
See #4
the only difference is the native jar.
- So you need only ONE jar/xml combo... Probably the v1.3 SQLCipher.jar, SQLCipher.xml
- You need to remove the dependson line for the native jar inside the libs xml
- You need to have TWO native jars in add libs folder. sqlcipher_native.jar (from V1.3) and sqlcipher_native12.jar (from V1.2)
- You need to use the Buildconfigurations to add the right native jar at runtime.

PD: Start with removing all THREE native jar from the additional libs folder.
put the two needed jars into the additional libs folder. sqlcioher_native.jar (101kb) and sqlcipher12.jar (102kb)
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
I did each step above, removed all, copied and named according to your instructions
Additional libraries:
upload_2017-3-30_5-55-30.png


Libraries look as below:
upload_2017-3-30_5-47-52.png

When I compile, I get:
B4A version: 6.80
Parsing code. (0.93s)
Compiling code. (1.43s)
Compiling layouts code. (0.06s)
Organizing libraries. (0.00s)
Generating R file. (0.18s)
Compiling debugger engine code. (8.59s)
Compiling generated Java code. (8.17s)
Convert byte code - optimized dex. Error
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lexample/EventDataSQLHelper;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
at com.android.dx.command.dexer.Main.processClass(Main.java:615)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:570)
at com.android.dx.command.dexer.Main.access$2(Main.java:546)
at com.android.dx.command.dexer.Main$2.processFileBytes(Main.java:514)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:537)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:449)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:236)
at com.android.dx.command.dexer.Main.run(Main.java:206)
at com.android.dx.command.dexer.Main.main(Main.java:179)
at com.android.dx.command.Main.main(Main.java:103)
1 error; aborting
Sorry to be so difficult...What am I doing wrong now?
UPDATE:
Apparently, during the COPYing, I copied an XML file that was not edited over my edited XML file. The DependsOn line was still in there...removed, now it is compiling.
but upon execution it gives
Fatal signal 6 (SIGABRT) at 0x00004a0d (code=-6), thread 18957 (rvey.b4a.survey)


Rusty
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but upon execution it gives
Fatal signal 6 (SIGABRT) at 0x00004a0d (code=-6), thread 18957 (rvey.b4a.survey)
I guess @Erel or someone other may help here.

I can´t, sorry. I just wanted to try to help you with this issue even if i do not use sqlcipher at all.
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
I appreciate all your help, Don :)
I hope Erel can figure this out, I'm sure it's something I've done wrong...
Regards,
Rusty
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
based on the huge different size of the library jar i have an idea

Please upload the two library jars...
V1.3 jar and V1.2 jar

Or better both (jar and xml from the both libs...)

I think it could be that the native jar is included in the bigger library jar. Or any other classes.... I just want to find out what the difference is
 
Upvote 0
Top