android-apt
插件已被弃用。
请查看迁移指南:
从 Android Gradle 插件版本 2.2 开始,先前由 android-apt 提供的所有功能现在都可以在 Android 插件中使用。
按照迁移指南中的说明可以删除 android-apt
并获取等效的功能。
迁移指南中的重要部分:
- 确保你使用的是 Android Gradle 2.2 或更新的插件。
- 从构建脚本中删除
android-apt
插件。- 将所有
apt
、androidTestApt
和testApt
依赖项更改为它们的新格式:
dependencies {
compile 'com.google.dagger:dagger:2.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
}
在Android Gradle插件中也有对此的明确检查,这就是你看到的:
使用不兼容的插件进行注解处理android-apt
未来的Android Gradle插件版本将不再兼容android-apt
的工作方式,这就是该检查的原因。
对我来说,当我使用Contentful的Vault
库时,遇到了这个错误,该库要求您包括:
apply plugin: 'com.neenbedankt.android-apt'
以及
compile 'com.contentful.vault:core:2.1.0'
apt 'com.contentful.vault:compiler:2.1.0'
你需要做的是删除apply plugin: 'com.neenbedankt.android-apt'
然后更改为:
compile 'com.contentful.vault:core:2.1.0'
apt 'com.contentful.vault:compiler:2.1.0'
到
annotationProcessor 'com.contentful.vault:compiler:2.1.0'
annotationProcessor 'com.contentful.vault:core:3.0.1'
您始终可以检查https://github.com/contentful/vault以获取最新版本。
移除 apt 插件
更改:
apt -> compile
testApt -> testAnnotationProcessor
androidTestApt -> androidTestAnnotationProcessor
在 build.gradle (app) 中的 defaultConfig 中添加:
vectorDrawables.useSupportLibrary = true
借鉴@Gabriele Mariotti的回答,他的回答已经很到位了,虽然没有明确说明。Gradle也认为这不是一个有效的选项,但实际上它也是可以的。对于androidTestApt
和testApt
,测试等效选项是androidTestAnnotationProcessor
和testAnnotationProcessor
。
例如:
testApt "com.google.dagger:dagger-compiler:$daggerVersion"
androidTestApt "com.google.dagger:dagger-compiler:$daggerVersion"
应该被更改为
testAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
apt {
arguments {
KEY "VALUE"
}
}
转换为:
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = ['KEY': 'VALUE']
}
}
}
}
android-apt
的工作方式,这就是进行该检查的原因。 - botteaap