dagger2的基本使用一

来源:互联网 发布:淘宝店装修模板自己做 编辑:程序博客网 时间:2024/05/17 18:48

dagger2是一种依赖注入框架,为了解决繁琐的依赖关系

基本使用

1 首先在根build中配置

buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:2.2.3'        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'    }}
2 在app的build中添加dependencies

dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {        exclude group: 'com.android.support', module: 'support-annotations'    })    compile 'com.android.support:appcompat-v7:25.3.1'    testCompile 'junit:junit:4.12'    //dagger2    compile 'com.google.dagger:dagger:2.10'    apt 'com.google.dagger:dagger-compiler:2.10'    provided 'org.glassfish:javax.annotation:10.0-b28'}
之后就可以正常的使用dagger2了

0 0
原创粉丝点击