Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
16
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@tomichan_jp

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

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'」するだけ。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
16
Help us understand the problem. What are the problem?