GreenDao入门教程:添加依赖,导入库文件

来源:互联网 发布:c语言最小公倍数算法 编辑:程序博客网 时间:2024/06/03 15:15

1. 在工程Projectbuild.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. 在项目Modelbuild.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. 添加请求网络的权限

  1. <uses-permission android:name="android.permission.INTERNET"/>  

4. 新建IApplication类继承Application,并在清单文件中配置(主要用于数据库的初始化配置操作)

  1. <application  
  2.        android:name=".IApplication"  


其它具体的代码,后续更新~~~

阅读全文
1 0
原创粉丝点击