1. 在工程Project的build.gradle里面
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() mavenCentral() // 当前Project的build.gradle添加GreenDao库文件 } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // // 当前Project的build.gradle添加GreenDao库依赖 // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
2. 在项目Model的build.gradle里面
apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' // 在项目的build.gradle里面添加GreenDao插件 android { compileSdkVersion 26 defaultConfig { applicationId "com.dhw.greendao" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } /** * 新建GreenDao的依赖作用域 */ greendao{ targetGenDir 'src/main/java' //固定格式:作用域代码文件夹 daoPackage 'com.dhw.greendao.dao' //固定格式:作用域代码指定的包名,根据自己Model的包名加上 .dao即可 schemaVersion 1 //固定格式:版本号 } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' //添加GreenDao及数据库database的依赖 compile 'org.greenrobot:greendao:3.2.2' compile 'net.zetetic:android-database-sqlcipher:3.5.7@aar' }
3. 添加请求网络的权限
- <uses-permission android:name="android.permission.INTERNET"/>
4. 新建IApplication类继承Application,并在清单文件中配置(主要用于数据库的初始化配置操作)
- <application
- android:name=".IApplication"
其它具体的代码,后续更新~~~