依赖
Root
buildscript {
repositories {
jcenter()
mavenCentral() // 1. add repository
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' //2. add plugin
}
}
Moudle
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao' // 1.apply plugin
dependencies {
implementation 'org.greenrobot:greendao:3.3.0' // 2.add library
}
greendao {
// 指定数据库schema版本号,迁移等操作会用到
schemaVersion 1
// 设置生成数据库文件的目录,默认是在build中,可以将生成的文件放到我们的java目录中
targetGenDir 'src/main/java'
// 设置生成的数据库相关文件的包名,默认为entity所在的包名
daoPackage 'com.yoho.greendao.gen'
}
创建一个需要生成数据库的Bean类
Bean类的 类名上面 加上 @Entity
是否让id自增
注:----------------------------id 必需是long 类型 且 l 必需 大写 L
地址改为 想要把数据库相关文件生成的位置的包名
改完锤一下
叮 叮 叮 d=====( ̄▽ ̄*)b
你的数据库生成完成 了
可以开始操作了