6

I tried integrating SQLCipher in my Android Application, using this link and also some stack-overflow links(but they are out-dated and differs from official document).

All the steps are correctly followed, and there is no error in the coding part. But at last, when I build the project, the error message I get is :

Error:(11, 0) Gradle DSL method not found: 'defaultConfig()' Possible causes:

  • The project 'android-database-sqlcipher-master1' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • Can anyone please help me to get rid of this error.

    Rashmin Javiya
    • 5,173
    • 3
    • 27
    • 49

    1 Answers1

    14

    add this to your build.gradle of your app and it should work out of the box:

    dependencies {
         compile 'net.zetetic:android-database-sqlcipher:3.5.2@aar'
         ...
    }
    

    In your code, you should load the 'native libraries' as this 'aar' file contains a few of them.

    SQLiteDatabase.loadLibs(context);
    

    NOTE that you should use the net.sqlcipher.database.SQLiteDatabase instead of android.database.sqlite.SQLiteDatabase, just like a couple of other SQLite classes.

    Alécio Carvalho
    • 13,481
    • 5
    • 68
    • 74
    • 1
      Can you please share the full implementation ? – Noman Jan 03 '16 at 10:30
    • 1
      You can read more info on SQLCipher and Android Studio's integration [here](http://lomza.totem-soft.com/tutorial-add-sqlcipher-to-your-android-app/). – lomza Mar 29 '16 at 19:33
    • 1
      Getting crash on line SQLiteDatabase.loadLibs(context); in samsung device with an error java.lang.UnsatisfiedLinkError: – Krunal Shah Jun 17 '16 at 07:28
    • How to open encrypted DB file to test DB, Do we have any supported tool. Any suggestion!! – CoDe Jul 15 '16 at 06:13
    • @KrunalShah have you got work arount or any fixed for error you getting as mentioned above. – Abdul Wahab Jul 20 '16 at 11:05
    • I got the solution but it was temporary, i clean the project after removing .idea file then run . its works, This crash happened because there is an other third party lib i used that also try to load its so file from libs. – Krunal Shah Jul 21 '16 at 06:55
    • @Alecio I m facing same Issue in Android Studio – Nancy Jain Jul 29 '16 at 11:38
    • @NancyJain after build the project there are some apks are generated in build folder as per the as per the architecture which you are include in build.gradle file, find out the architecture of your device and install that apk in your device which are in build folder. – Krunal Shah Oct 12 '16 at 13:21
    • Also you will need SqlCipher 3.5.6 for Android N. Previous versions of SqlCipher won't work correctly from Android 7(N) onwards. https://www.zetetic.net/blog/2016/6/23/sqlcipher-android-release-n-support/ – turtleboy Mar 14 '17 at 15:30