Android Studio 2.2如何在没有android-apt插件的情况下应用dagger2 [英] android studio 2.2 how to apply dagger2 without android-apt plugin
问题描述
我的项目build.gradle
my project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-alpha3'
classpath 'com.google.dagger:dagger-compiler:2.2'
classpath 'com.google.guava:guava:19.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的模块build.gradle
my module build.gradle
android {
compileSdkVersion 24
buildToolsVersion '24.0.0'
defaultConfig {
applicationId "com.aber.app.acgtalk"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
ext {
supportLibVersion = '24.0.0'
}
dependencies {
compile 'com.google.dagger:dagger:2.2'
annotationProcessor 'com.google.dagger:dagger-compiler:2.2'
debugAnnotationProcessor 'com.google.dagger:dagger-compiler:2.2'
provided 'javax.annotation:jsr250-api:1.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:${supportLibVersion}";
compile "com.android.support:recyclerview-v7:${supportLibVersion}";
compile "com.android.support:design:${supportLibVersion}";
compile "com.android.support:support-v13:${supportLibVersion}";
compile "com.android.support:support-annotations:${supportLibVersion}";
compile "com.android.support:gridlayout-v7:${supportLibVersion}";
compile "com.android.support:cardview-v7:${supportLibVersion}";
compile "com.android.support:preference-v14:${supportLibVersion}";
compile 'com.squareup.okhttp3:okhttp:3.2.0';
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
}
这有什么问题,如何在Android Studio 2.2中使用注释处理器功能,如何正确配置dagger2注释处理器?
what's wrong with this,how to using the annotationProcessor function within the Android studio 2.2 ,how to conifg the dagger2 annotation processor correctly?
推荐答案
是的,对于android gradle插件2.2.0版,注释处理不再需要android-apt
插件. apt
函数包含在最新的android gradle插件中.现在称为annotationProcessor
,这就是您的构建脚本中的内容.但是,脚本中有一些配置错误的东西.
Yes, with android gradle plugin 2.2.0 release, the android-apt
plugin is no longer needed for annotation processing. The apt
function was included in the latest android gradle plugin. It's called annotationProcessor
now which was what you had in your build script. However, there were a few misconfigured stuff in the script.
首先,不应将Dagger编译器添加到classpath中.因此,请删除以下行:classpath 'com.google.dagger:dagger-compiler:2.2'
.
First of all, the dagger compiler should not be added to classpath. So remove this line: classpath 'com.google.dagger:dagger-compiler:2.2'
.
并且您正在使用android gradle插件版本alpha3
.尝试使用最新版本,因此请更改为classpath 'com.android.tools.build:gradle:2.2.2'
.
And you are using android gradle plugin version alpha3
. Try to use the latest version, so change to classpath 'com.android.tools.build:gradle:2.2.2'
.
依赖声明块看起来合法.因此,请尝试进行上述更改以查看是否可行.
The dependency declaration block looks legit. So try to make the above changes to see if it would work.
这篇关于Android Studio 2.2如何在没有android-apt插件的情况下应用dagger2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!