步骤一、在自己的build.gradle中加入这些配置
- 在app的build.gradle中
apply plugin: ‘org.greenrobot.greendao’
greendao {
//数据库的schema版本,也可以理解为数据库版本号
schemaVersion 1
//设置DaoMaster、DaoSession、Dao包名,也就是要放置这些类的包的全路径。
daoPackage ‘tsou.com.simple.greendaoforkotlin.greendao’
//设置DaoMaster、DaoSession、Dao目录
targetGenDir ‘src/main/java’
}
dependencies
compile ‘org.greenrobot:greendao:3.2.0’
}
- 在项目的build.gradle中
buildscript {
ext.kotlin_version = ‘1.1.50’
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:3.0.0-beta7’
classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”
classpath ‘org.greenrobot:greendao-gradle-plugin:3.2.0’
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
步骤二、创建Student实体类
package tsou.com.simple.greendaoforkotlin.bean;
import android.support.annotation.Keep;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Generated;
@Entity(generateConstructors = false)
public class Student {
@Id
private Long id;
private String name;
private int age;
public Student() {
}
@Keep
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public Student(Long id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
@Keep
public Long getId() {
return id;
}
@Keep
public void se