Accessing sqlcipher from native code on Andriod

I’ve been using sqlcipher on Android from within a native library that I’ve developed. I’m going through the process of upgrading to 3.5.3 from 3.4.0 to address the Android N compatibility and ran across an issue that I believe is due to the combining of the multiple .so’s into the single libsqlcipher.so.

When I initially did the development, I was able to avoid using the JNI layer since I was accessing sqlcipher on Android from within my own native library. Note that I don’t include the sqlcipher.jar file in my application. When I initially upgraded to 3.5.3, my code failed to load libsqlcipher since the JNI OnLoad function was going out and trying to hook up all the references from the jar.

My immediate fix was to comment out the code in JNI OnLoad that does this, and I’m now able to run as I used to, accessing everything from my own native library.

Is there a better way to accomplish this?

Hello @joshblomberg - just to clarify here are you including SQLCipher using Gradle or manually packaging via the zip package?

Hi Stephen,

I’m linking against libsqlcipher.so from within another native library that I’m developing. My native library ends up getting manually linked into an Android app. We don’t include the sqlcipher.jar since it’s not needed and also to reduce the dex limit. Everything we do with sqlcipher is all on the native side of the house.

Thanks,
Josh

Hi @joshblomberg

It sounds as if your approach is working by commenting out the JNI_OnLoad components. An alternative approach would be to create a standalone NDK project, or an extension to your existing NDK project where you compile the SQLCipher core amalgamation and make it available to your library via a LOCAL_MODULE, this may make integrating upstream changes easier in the future.