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

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"  


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值