Android Studio uses the Gradle-based build system, so project integration is slightly different than our standard integration guide within an Android project. In this case, the location of the native libraries and the assets directory differ.
Once you have created your application project structure within Android Studio and have downloaded the SQLCipher for Android binaries, open the application folder structure. Navigate to the app\src\main
directory and create two child folders, jniLibs
and assets
. Within the jniLibs
directory, copy over the platform specific folders that contain the native .so files, these are found in the libs
folder of SQLCipher for Android binary distribution. Next, copy over icudt46l.zip
file from the assets
directory into your applications assets
directory. Finally, copy over sqlcipher.jar
, guava-r09.jar
, and commons-codec.jar
to the app\libs
directory. Once completed, your folder structure should look similar to this below:
Next, open your application within Android Studio and navigate to File → Project Structure…, select
app
from the Modules section on the left pane, then click on the Dependencies tab. Press the + sign at the bottom of the dependencies pane and add sqlcipher.jar
, guava-r09.jar
, and commons-codec.jar
as file dependencies. It should look similar to this:
You should now be able to use SQLCipher for Android within Android Studio:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
SQLiteDatabase.loadLibs(this);
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(":memory:", "Password1!", null);
Cursor cursor = database.rawQuery("PRAGMA cipher_version;", null);
cursor.moveToFirst();
String version = cursor.getString(0);
Log.i(TAG, String.format("SQLCipher version:%s", version));
cursor.close();
database.close();
}