Android Studio(Beta v0.8.6) and SQLCipher(v3.1.0) integration
Asked Answered
R

0

6

I have been searching for a solution to my problem a long time and I just want to share my solution to others who might have the same problem.

I was coming from the Eclipse IDE developing an android app and I wanted to check out the Android Studio IDE. So I downloaded the current Android Studio(BETA v0.8.6) and so far I really like what the are doing with the Android Studio.

My Problem: I was using the SQLCipher libraries to include an encrypted database into my project. Unfortunately integration of SQLCipher into Android Studio doesn't work like they say on the official SQLCipher website (since the howto is written for the Eclipse IDE). So I was searching the web for a solution to integrate SQLCipher into Android Studio because I wasn't able to import it into my main activity java class.

My Solution: You download the SQLCipher build from the official website. In that folder you will see two folders. An "assets" folder and a "libs" folder.

Within the "libs" folder there are your *.jar files and some folders for each supported architecture with some *.so files within them.

Now you do the following:

  1. Go to your project-folder (standard in: C:\Users\\AndroidStudioProjects\)
  2. Open the "app" folder
  3. Copy the three .jar files (commons-codec, guava-r09, sqlcipher) into the "lib" folder.
  4. Now go to: app\src\main and create two folders: "assets" and "jniLibs".
  5. Copy the icudt46l.zip file into the "assets" folder.
  6. Copy the "armeabi", "armeabi-v7a" and "x86" folders into the "jniLibs" folder.

Now start Android Studio and open your project. In Android Studio you see the files in tree view at your left.

  1. Expand your "app" folder wihtin Android Studio so you can see the "build.gradle" file.
  2. Open the "build.gradle" file.
  3. Now within the grade.build file make sure this code snippets is included at the bottom of the file:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    }
    
  4. It should now look similar to this:

    apply plugin: 'com.android.application'
    android {
        compileSdkVersion 'android-L'
        buildToolsVersion "20.0.0"
        defaultConfig {
            applicationId "com.example.testapp"
            minSdkVersion 15
            targetSdkVersion 'L'
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                runProguard false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        sourceSets {
            main {
                jniLibs.srcDirs = ['libs']
            }
        }
    }
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    }
    

Finally the import for SQLCipher should now be working. It's important that you create the jniLibs folder with exactly that name! Otherwise it won't work.

I wanted to add pictures as well, but I don't have any sort of credit points yet to do so. As soon as I have these I will add the pictures I made to this post.

Greetz, Steffen

Redstart answered 19/8, 2014 at 18:17 Comment(2)
as for 0.8.9 you needn't {sourceSets { main...} }: in my setup it works without it - and does not works with, cyst adding jniLibs does the trickTropism
Hi, I have integrated as per your suggestion but getting below error.java.lang.UnsatisfiedLinkError: Couldn't load stlport_shared from loader dalvik.system.PathClassLoader[DexPathList[[zip file findLibrary returned null at java.lang.Runtime.loadLibrary(Runtime.java:358)Scabby

© 2022 - 2024 — McMap. All rights reserved.