LoginSignup
16

More than 5 years have passed since last update.

AndroidStudioでSQLiteを暗号化するSQLCipherを使う

Posted at

AndroidStudioでSQLiteを暗号化する、SQLCipherを取り込むのに苦労したので備忘録的に。

まずは、SQLCipherの下記ページからAndroid用のライブラリ一式をダウンロード。
http://sqlcipher.net/open-source/
https://s3.amazonaws.com/sqlcipher/SQLCipher+for+Android+v3.0.2.zip

ダウンロードしたライブラリを解凍すると、下記のような構成になっている。
SQLCipher
|- assets/
|- libs/
|- READEME
|- SQLCIPHER_LICENSE

次に、プロジェクト上のapp配下に、解凍したassetsとlibsをコピー
スクリーンショット 2014-02-21 01.56.27.png

app/build.gradleを更新。

build.gradle

android {
    compileSdkVersion 18
    buildToolsVersion "19.0.1"

    ....
    sourceSets {
        main {
            assets {
                srcDirs = ['assets']
            }
        }
    }
}

dependencies {
    ....
    compile files('libs/commons-codec.jar')
    compile files('libs/guava-r09.jar')
    compile files('libs/sqlcipher.jar')
    compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}

// for native modules
task copyNativeLibs(type: Copy) {
    from('libs') { include '**/*.so' }
    into new File(buildDir, 'native-libs')
}
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
    pkgTask.jniFolders = new HashSet<File>()
    pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))
}
clean.dependsOn 'cleanCopyNativeLibs'

ここまでできれば後は、「Run 'app'」するだけ。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16