Dagger2依赖-Gradle [英] Dagger2 dependency - Gradle

查看:289
本文介绍了Dagger2依赖-Gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Dagger2添加到我在Android Studio中的项目中,但是找不到合适的依赖项粘贴到build.gradle中.您能帮忙给我发送正确的电话吗?

I'm trying to add Dagger2 to my project in Android Studio but I can't find proper dependency to paste in build.gradle. Could you help and send me the proper line?

推荐答案

在Android Studio 2上安装Dagger 2

// Application build.gradle
dependencies {
    compile 'com.google.dagger:dagger:2.4'
    annotationProcessor "com.google.dagger:dagger-compiler:2.4"
}

Maven存储库:

在Maven存储库中找到上述依赖项的最新版本:

Find the latest versions of the above dependencies in the Maven Repository:

  • dagger
  • dagger-compiler

较旧版本的Android Studio需要android-apt进行注释处理.

Older versions of Android Studio need android-apt for annotation processing.

// Project build.gradle
buildscript {
    dependencies {
        // Assists in working with annotation processors for Android Studio.
        // No longer needed with Android Studio 2.2+
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}
apply plugin: 'com.neenbedankt.android-apt'

还有

// Application build.gradle
dependencies {
    compile 'com.google.dagger:dagger:2.4'
    apt "com.google.dagger:dagger-compiler:2.4"
}


注意:匕首< 2.1

匕首< 2.1-SNAPSHOT Dagger生成的代码中使用的@Generated批注需要javax.annotation(请参见 github.com/google/dagger/issues/95 ).该注释未包含在Android API jar中,因此您需要使用以下库之一(查看差异):


Notes: Dagger < 2.1

For Dagger < 2.1-SNAPSHOT the javax.annotation is needed for the @Generated annotation used in Dagger generated code (see github.com/google/dagger/issues/95). The annotation is not included in the Android API jar, so you'll need to use one of these libraries (see differences):

// Application build.gradle
dependencies {
    compile 'javax.annotation:jsr250-api:1.0'
}

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆