升级到Android Studio 2.3后,android-apt的插件不兼容

Bro*_*onx 97 android gradle android-studio android-apt

从2.2升级到2.3后,我看到了这个警告

在此输入图像描述

当我尝试编译项目时,我看到了这个编译错误

在此输入图像描述

如何在不降级到之前的gradle版本的情况下解决此问题?是否有任何更新的android-apt可以解决这个问题?

Gab*_*tti 176

android-apt插件已被弃用.
点击此处查看迁移指南:

从Android Gradle插件版本2.2开始,Android-apt之前提供的所有功能现在都可以在Android插件中使用.

您可以android-apt按照迁移指南进行删除,以获得相同的功能.

迁移指南中的重要部分:

  • 确保您使用的是Android Gradle 2.2插件或更新版本.
  • android-apt从构建脚本中删除插件
  • 更改所有apt,androidTestApttestApt依赖他们的新格式:
dependencies {
   compile 'com.google.dagger:dagger:2.0'
   annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
}
Run Code Online (Sandbox Code Playgroud)

同样在Android Gradle插件中有一个明确的检查,这是你看到的:

使用不兼容的插件进行注释处理android-apt

未来的Android Gradle插件版本android-apt工作方式不兼容,这就是检查的原因.


ojo*_*ifu 45

对我来说,我在使用Contentful的Vault库时出现此错误,该库指定您包含:

apply plugin: 'com.neenbedankt.android-apt'
Run Code Online (Sandbox Code Playgroud)

compile 'com.contentful.vault:core:2.1.0'
apt 'com.contentful.vault:compiler:2.1.0'
Run Code Online (Sandbox Code Playgroud)

您需要做的是删除 apply plugin: 'com.neenbedankt.android-apt'

然后改变:

compile 'com.contentful.vault:core:2.1.0'
apt 'com.contentful.vault:compiler:2.1.0'
Run Code Online (Sandbox Code Playgroud)

annotationProcessor 'com.contentful.vault:compiler:2.1.0'
annotationProcessor 'com.contentful.vault:core:3.0.1'
Run Code Online (Sandbox Code Playgroud)

您可以随时查看https://github.com/contentful/vault以获取最新版本


Oct*_*nel 15

  1. 删除apt插件

  2. 更改:

    apt - >编译

    testApt - > testAnnotationProcessor

    androidTestApt - > androidTestAnnotationProcessor

  3. 在build.gradle(app)中,添加到defaultConfig:

vectorDrawables.useSupportLibrary = true


sup*_*rdo 6

在@Gabriele Mariotti抄袭@Gabriele Mariotti,因为他的答案非常明确并暗示了这一点,但并没有说出来.Gradle也不建议将此作为有效选项,尽管它也是如此.测试相当于androidTestApttestAptandroidTestAnnotationProcessortestAnnotationProcessor.

例:

testApt "com.google.dagger:dagger-compiler:$daggerVersion"
androidTestApt "com.google.dagger:dagger-compiler:$daggerVersion"
Run Code Online (Sandbox Code Playgroud)

应该改为

testAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
Run Code Online (Sandbox Code Playgroud)