GreenDao配置步骤
Project下的build.gradle文件加入
buildscript {
repositories {
google()
jcenter()
mavenCentral() // 添加代码仓库 步骤1
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
//步骤2
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' //本地Greendao数据库
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Module下的build.gradle文件加入
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao' // apply plugin 步骤3
android {
........
//greendao配置 步骤5
greendao {
//数据库版本号,升级时修改
schemaVersion 1
//生成的DAO,DaoMaster和DaoSession的包路径。把com.mypro修改为与表实体所在的包路径相同(自己的项目主包路径)
daoPackage 'com.mypro.db'
//生成源文件的路径。默认源文件目录是在build目录中的(build/generated/source/greendao)
targetGenDir 'src/main/java'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//greenDAO配置 步骤4
implementation 'org.greenrobot:greendao:3.2.2' // add library
implementation 'org.greenrobot:greendao-generator:3.2.2'
}
然后通过AndroidStudio build/Make Project 从新编译