Android第三方工具库Android开发Android进阶之路

GreenDao集成教程(一) GD基本集成

2017-11-27  本文已影响48人  冷寒

GreenDao引用

Project-->Gradle

buildscript {
    
    repositories {
        ...
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // 添加插件 更好支持GreenDao
        ...
    }
}

allprojects {
    repositories {
        ...
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

APP-->Gradle

apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao' // 添加应用依赖插件
android {
    compileSdkVersion 26
    defaultConfig {
        ...
    }
    buildTypes {
        ...
    }

    // 配置GreenDao基本参数
    greendao {
        schemaVersion 1 //当前数据库版本
    }
}

dependencies {
    ...
    //log
    compile 'com.orhanobut:logger:1.15'
    //数据库调试
    debugCompile 'com.amitshekhar.android:debug-db:1.0.0'
    //GreenDao
    compile 'org.greenrobot:greendao:3.2.2' // 添加GreenDao库
}

定义实体Entity

@Entity
public class Member {
    @Id(autoincrement = true) // id自增长
    private Long memId; // 学院id

    private String memName; // 学员姓名

    private int memSex; // 学员性别
}

编译自动生成GreenDAO相关工具类以及SQL等

DEMO入口

上一篇下一篇

猜你喜欢

热点阅读