如何将Greendao与sqlcipher集成

时间:2017-03-22 07:11:11

标签: android greendao sqlcipher-android

我想在android studio中集成Greendao和Sqlcipher以获得加密的数据库。我使用sqlcipher-for-android

我将这些添加到我的app / build.gradle

    compile 'org.greenrobot:greendao:3.2.0'
compile 'org.greenrobot:greendao-generator:3.2.0'
compile 'net.zetetic:android-database-sqlcipher:3.5.6@aar'

我从Here下载了v3.5.6 在第二步中我必须执行这些命令

% unzip sqlcipher-for-android-v3.5.6.zip
% mkdir -p app/libs
% cp sqlcipher-for-android-v3.5.6/sqlcipher.jar app/libs
% cp -r sqlcipher-for-android-v3.5.6/armeabi \
    sqlcipher-for-android-v3.5.6/armeabi-v7a \
    sqlcipher-for-android-v3.5.6/x86
    sqlcipher-for-android-v3.5.6/x86_64 \
    sqlcipher-for-android-v3.5.6/arm64_v8a app/src/main/jniLibs/

但是zip文件中没有sqlcipher.jar,armeabi,armeabi-v7a,x86和...

我错过了什么或做错了吗? 请帮忙

1 个答案:

答案 0 :(得分:1)

将此与example进行比较解决了问题

buildscript {
repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.1'
    classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
}
}

buildscript {
repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.1'
    classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
}
}

apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'

android {
buildToolsVersion '25.0.2'
compileSdkVersion 25

defaultConfig {
    applicationId "org.greenrobot.greendao.example"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "3"

    testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
}

greendao {
schemaVersion 1000
}

dependencies {
compile 'org.greenrobot:greendao:3.2.2'

// This is only needed if you want to use encrypted databases
compile 'net.zetetic:android-database-sqlcipher:3.5.6'

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
}

uploadArchives.enabled = falseapply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'

android {
buildToolsVersion '25.0.2'
compileSdkVersion 25

defaultConfig {
    applicationId "org.greenrobot.greendao.example"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "3"

    testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
}

greendao {
schemaVersion 1000
}

dependencies {
compile 'org.greenrobot:greendao:3.2.2'

// This is only needed if you want to use encrypted databases
compile 'net.zetetic:android-database-sqlcipher:3.5.6'

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
}

uploadArchives.enabled = false

以及以下代码:

package org.greenrobot.greendao.example;

import android.app.Application;

import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.example.DaoMaster.DevOpenHelper;

public class App extends Application {
/** A flag to show how easily you can switch from standard SQLite to the 
encrypted SQLCipher. */
public static final boolean ENCRYPTED = true;

private DaoSession daoSession;

@Override
public void onCreate() {
    super.onCreate();

    DevOpenHelper helper = new DevOpenHelper(this, ENCRYPTED ? "notes-db-encrypted" : "notes-db");
    Database db = ENCRYPTED ? helper.getEncryptedWritableDb("super-secret") : helper.getWritableDb();
    daoSession = new DaoMaster(db).newSession();
}

public DaoSession getDaoSession() {
    return daoSession;
}
}