Android Question Very large APK using sqlcipher

ernschd

Active Member
Licensed User
Longtime User
Hello,

I wanted to change an app from sqlite to sqlcipher to work with encryption. In doing so, I noticed that the APK is getting very large, which is probably due to the different versions of the libsqlcipher.so file.

These are in the APK in the directories:
  • lib\arm64-v8a\libsqlcipher.so
  • lib\armeabi\libsqlcipher.so
  • lib\armeabi-v7a\libsqlcipher.so
  • lib\x86\libsqlcipher.so
  • lib\x86_64\libsqlcipher.so

Is there any way in B4A that e.g. no x86 variant is created?
I could of course delete the file manually from the APK, but then I would probably have to adjust some things. Also, there is always the risk that the deletion is forgotten during an update.

Thanks in advance!
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
If the size of the APK is a problem, I wonder if you realize that encrypting a database also results in a much larger database length. Another issue is that you may have a database solution in your program that conflicts with encryption. If you use a lot of public information, it may be useful to encrypt only the field information you want to protect.
 
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
The size of the APK was around 5 MB before an 15 MB after including sqlcipher.
The database was the same size in my case (one database is even smaller).
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
The size of the APK was around 5 MB before an 15 MB after including sqlcipher.
The database was the same size in my case (one database is even smaller).
15mb is not very large!
with today 4g/5g it would take few seconds to download.
 
Upvote 0

Num3

Active Member
Licensed User
Longtime User
You can delete these safely (from inside the library aar, not the apk):
  • lib\x86\libsqlcipher.so
  • lib\x86_64\libsqlcipher.so
I do it all the time.
I keep a sqlite version for android and one for x64 this way, just by renaming the libray JAR and removing the uncessary junk from inside.
It will save you 3Mb in size...
 
Last edited:
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
Ok, I hoped there was a option like this (a Module Attribute or something):
B4X:
#ExcludeLibrary: x86
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Read this;

 
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
When I remove the x86 libraries and try to install the APK via ADB, I get this error message:
Bash:
adb: failed to install SqlCipher.apk: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Failed to collect certificates from /data/app/vmdl75551812.tmp/base.apk: File lib/x86_64/libsqlcipher.so in manifest does not exist]

Which manifest is meant here?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Unfortunately, I still didn't find a solution...
Encrypting a SQL database has its price. One of them is a larger memory footprint. On the one hand, because in addition to the encryption routines, these must also be linked and included in your program.
You can determine how much that is by looking at the size of a test project. First with an empty database unencrypted, and then the same project with the same empty but encrypted database. Then you will find the extra memory that you cannot avoid.

Then I wrote to you before that encrypting data simply leads to more memory consumption. At the time, I also advised you to only encrypt necessary information because encrypting public information takes up space, but contributes nothing to the security of public information.

You could test encryption with the internal library (J)B4XEncryption which may require less memory.
 
Upvote 0

thinktank

Member
Try to compact sqlite database and then compile your app and check apk size... Sometimes when we play with sqlite databases, the size gradually increases, it is good practice to compact database before compiling apk
 
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
Thanks for your reply.

I do understand that encrypting a sqlite has a higher overhead. But our app is only used by our customers, so we know that there are no x86 devices in use. That's why I would like to remove the libraries that are not needed.

The files encrypted with the internal B4XEncryption library cannot be decrypted on the PC, as far as I know?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Upvote 0

agraham

Expert
Licensed User
Longtime User
C# source code and dll for desktop here for .NET desktop use. It uses Bouncy Castle but I can't think of a reason why it couldn't use the .NET AES class.
 
Upvote 0
Top