Android Studio Integration

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();
    }

Should I follow the above steps? as Android Studio and SQLCipher Library are updated. This seems to be out dated.
Thank You.

Hello @farhanK501

Yes, these are still the correct steps to follow for SQLCipher for Android integration within an Android Studio project.

Thank you for the reply.
I just copied down the sqlcipher.jar, sqlcipher-javadoc.jar into root of my already created '“libs” folder, and copied other *.so files into proper architecture. But when I call SQLiteDatabase.loadLibs( this ); into my mainActivity’s on onCreate() method…
I get this…

03-25 12:59:57.500    1826-1826/com.myactivity.mainActivity E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.myactivity.mainActivity, PID: 1826
    java.lang.UnsatisfiedLinkError: Couldn't load stlport_shared from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.myactivity.mainActivity1.apk"],nativeLibraryDirectories=[/data/app-lib/com.myactivity.mainActivity-1, /system/lib]]]: findLibrary returned null
            at java.lang.Runtime.loadLibrary(Runtime.java:358)

Further more there is no libraries in data/data/myactivity/lib…
As I see online there should be those libraries added?
Sorry for noobish question but I got my all day on this and can’t figure out what is going on…
I am new to android…
any help will be great full.
ThankYou.
I am on Mac.
Using AndroidStudio latest.

Hello @farhanK501

It is difficult to say what the issue might be, though my initial thought is it may be project configuration related. Did you also copy over the icudt46l.zip file into your assets folder? SQLCipher for Android no longer depends on commons-codec.jar, nor guava-r09.jar, otherwise your folder structure should match what is displayed above.

1 Like

Can I ask @developernotes which binary download file did you download? I downloaded from https://github.com/sqlcipher/android-database-sqlcipher/releases/tag/v3.3.1-2 and I can’t seem to match up the files in that to your instructions.
Thanks,
James

Hello @ShelterJames

The instructions above are for integrating the zip binary distribution of SQLCipher for Android. If you are using the community edition of SQLCipher for Android, we only distribute SQLCipher for Android as a AAR package now which streamlines library installation with Gradle. The AAR packaging name can be found here.

1 Like

A post was split to a new topic: Missing libstlport_shared.so

Hi Nick parker,

I have integrated the sqlcipher in my project using Android studio. i have followed the steps,

 1. Added the armeabi, armeabi-v7a,x86 folder to jniLibs.
 2. Added the icudt461.zip to assets folder.
 3. Added the sqlcipher.jar, guava-r09.jar,commons-codec.jar to libs folder.

Finally, I have run the project , i got the exception as

" java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.myapp.myapp-2/base.apk”],nativeLibraryDirectories=[/data/app/com.myapp.myapp-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn’t find “libstlport_shared.so” "

I have created the new folder as “arm64”,“arm64-v8a” and paste the “libstlport_shared.so” from armeabi. again run the project, that issue is not fixed.

i’m searching to fix the issue through tje internet , i couldn’t fix the issue,

please give the suggestion

Hi @mohan

Are you using the community edition of SQLCipher for Android? If so, the easiest way to integrate the library is following these steps. You can not include 64-bit libraries with SQLCipher for Android at this time, more information can be found here.

HI Nick ,
Thanks for reply. Now the problem is fixed. The problem is “Native Library Support”.

A post was merged into an existing topic: How to use SQLCipher