You might consider moving the SQLiteDatabase.loadLibs(this);
to your application subclass of net.sqlcipher.database.SQLiteOpenHelper
. You can then pass the static instance of your Application
subclass as its argument. Something like the following might be an example:
public class SchemaManager extends net.sqlcipher.database.SQLiteOpenHelper {
private static SchemaManager instance;
public static synchronized SchemaManager getInstance() {
if(instance == null) {
SQLiteDatabase.loadLibs(YourApplication.getInstance());
instance = new SchemaManager(…)
}
return instance;
}
}
With regard to the exception that was provided, the Java routine calls into a JNI layer that calls sqlite3_open_v2
, setting the soft heap limit and setting the busy timeout. I would suggest adding logging locally to verify you are passing a valid path and a non null passphrase when attempting to acquire the SQLiteDatabase
instance when you get a crash. Calling SQLiteDatabase.loadLibs(this);
multiple times shouldn't cause a noticeable performance impact, much of what occurs are calls to System.loadLibrary(…)
which get mapped into Runtime.getRuntime().loadLibrary(…)
, once a dynamic library has been loaded, subsequent calls are ignored.