如何包含匕首2?

How to include dagger 2?

我正在尝试使用 Dagger 2 进行依赖注入。目前我正在添加这样的依赖项。

在build.gradle

dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}

在app/build.gradle

apply plugin: 'com.neenbedankt.android-apt'


dependencies {
    testCompile 'junit:junit:
    compile 'com.android.support:appcompat-v7:23.2.0'
    apt 'com.google.dagger:dagger-compiler:2.2'
    compile 'com.google.dagger:dagger:2.2'
    provided 'javax.annotation:jsr250-api:1.0'
}

问题是,我们正在创建一个 SDK(模块),它将被其他应用程序包含,所以我不想在 build.gradle 中包含依赖项。因此,我将不得不告诉其他应用程序在它们的主 build.gradle 文件中包含 Dagger2 依赖项。

此外,如果有任何方法可以使用 jar 包含 dagger 库,请告诉我。

提前致谢:)

试试这个

将此添加到您的 build.gradle

dependencies {
 // other classpath definitions here
 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}

然后在你的 app/build.gradle:

 apply plugin: 'com.neenbedankt.android-apt'

 dependencies {
    // apt command comes from the android-apt plugin
   apt 'com.google.dagger:dagger-compiler:2.2'
   compile 'com.google.dagger:dagger:2.2'
   provided 'javax.annotation:jsr250-api:1.0'
 }

请注意,提供的关键字指的是仅在编译时需要的依赖项。

希望对您有所帮助