- Module下添加:
dependencies {
compile 'org.greenrobot:greendao:3.2.0'
}
apply plugin: 'org.greenrobot.greendao' - Project下添加:
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
greendao的Build.gradle:
compile 'org.greenrobot:greendao-generator:3.2.0'
(加了这句就【不要加】第1点的apply plugin: 'org.greenrobot.greendao' ,会造成生成的类重复)
-
新建Module:
File——New Module——Java Library——Next——
Finish.
-
打开新建的MyGreenGenerator类:
public static void main(String[] args) throws Exception {
Schema schema=new Schema(1,"com.carrie.dailytask.dao"); //com.carrie.dailytask是package name,dao是新建的包
addTask(schema); //添加Task表
schema.enableKeepSectionsByDefault();
new DaoGenerator().generateAll(schema,"../DailyTask/app/src/main/java");//app所在路径
}private static void addTask(Schema schema){ Entity entity=schema.addEntity("Task"); entity.addIdProperty(); entity.addStringProperty("title").unique().notNull(); entity.implementsSerializable(); }
接下来运行Java类:
选中MyGreenGenerator类,右键——Run 'MyGreenGenerator...main()'
会打印出如下的Log信息
然后在app包dao目录下,看到生成的DaoMaster、DaoSession等