How to hide or exclude sqlcipher from robolectric?


We were working on building a significant new feature for our app.

To speed development, we tried to build the feature independently of our app, and then bring it over.

Worked for iOS, not so much for Android.

Current issue is that the test suite is written using Robolectric for speed of running the tests…however, now that we’re trying to run the tests in the full app, we realise that we didn’t use sqlcipher in the independent build.

So, when I try to run a test case now, I get this error:
java.lang.UnsatisfiedLinkError: no sqlcipher in java.library.path

at java.lang.ClassLoader.loadLibrary(
at java.lang.Runtime.loadLibrary0(
at java.lang.System.loadLibrary(
at net.sqlcipher.database.SQLiteDatabase.loadLibs(
at net.sqlcipher.database.SQLiteDatabase.loadLibs(
at com.crowdlab.CLDatabase.initialiseDatabase(
at com.crowdlab.CLDatabase.initialise(
at com.crowdlab.BaseApplication.onCreate(
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(
at org.robolectric.RobolectricTestRunner.setUpApplicationState(
at org.robolectric.RobolectricTestRunner$2.evaluate(
at org.robolectric.RobolectricTestRunner.runChild(
at org.robolectric.RobolectricTestRunner.runChild(
at org.junit.runners.ParentRunner$
at org.junit.runners.ParentRunner$1.schedule(
at org.junit.runners.ParentRunner.runChildren(
at org.junit.runners.ParentRunner.access$000(
at org.junit.runners.ParentRunner$2.evaluate(
at org.robolectric.RobolectricTestRunner$1.evaluate(
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(
at com.intellij.rt.execution.junit.JUnitStarter.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.intellij.rt.execution.application.AppMain.main(

Fair enough. Is there a way to get sqlcipher to play nicely with Robolectric (such as shadows, maybe), or to tell Robolectric to ignore sqlcipher?


Hello @kcorey

Unfortunately SQLCipher for Android does not interoperate with Robolectric well because Robolectic runs on the desktop JVM, SQLCipher for Android includes native libraries built to target different Android CPU architectures. Two possible approaches to consider:

  1. Utilize mocks at runtime for tests that interface with a data layer. The drawback here is that you cannot actually test the various SQL commands you might execute within the running application.
  2. Consider an analagous approach which is used within the SQLCipher for Android test suite. In this case, a test runner executes tests on device/emulator. The pro here is the ability to execute the same queries against a real database on different device(s)/emulator(s). The drawback is speed; which is no way near as fast as typical JUnit style tests.


Thanks for the quick answer…but…ouch!

For the record, saw a post for another approach, where you use two different OpenHelpers, one for secure and one for not secure:

Hrm…going through the options:

For your #1, I’d need to rewrite (or at least check) the interfaces on 1000+ classes to change how we use the database.

For your #2, I’d have slower tests, which is kinda the problem we were hoping to solve.

For the link above, I’d need to revisit the 1000+ classes again…

Or finally just rewrite tests for 20 classes to not use Robolectric.

Guess I’m rewriting tests. :slight_smile: