安卓工作室 3.0 注解处理器

14

构建项目后,我得到以下错误:

Error:android-apt plugin is incompatible with the Android Gradle plugin.  Please use 'annotationProcessor' configuration instead.

我尝试在每个implementation后面添加annotationProcessor '.....',但没有成功摆脱错误。

这是在升级android studio到最新版本(3.0)之后出现的问题。

编辑:

defaultConfig中添加includeCompileClasspath true也没有帮助:

    javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }

有什么解决方案吗?


你找到解决方案了吗? - Zakharov Roman
5
是的,这是因为领域的原因发生了,我将领域库更新到最新版本,因为某些旧版本正在使用adt-plugin。 - Marian Pavel
@MarianPavel 请指定解决您问题的最新版本的realm。 - EmptyData
@EmptyData 最新的稳定版本是4.3.4,而最新的测试版是5.0.0-BETA1。 - ASN
2个回答

32

首先,在升级后,Gradle有些变化。

为了解决这个问题,重要的是升级到最新版本的Gradle。

这意味着你需要为你的构建 Gradle 添加正确的版本,目前是:

 dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
 }
下一步是删除不再需要的android-apt,只需要保留apply plugin: 'com.android.application'。完成后,请将依赖从compile更改为implementation,从apt更改为annotationProcessor,从testCompile更改为androidTestImplementation。如果您已经完成了这些步骤,请使缓存失效并重新启动,这非常重要。然后它应该能够正常工作。您可以在以下链接中找到使用最新版本的可用Gradle文件:app build.gradleproject build.gradle。顺带一提:许多人仍在使用旧版本的Realm,请更新至最新版本,因为旧版本仍在使用“android-apt”标记。

2

您需要在应用级别的Gradle中添加annotationProcessorOptions

android {    
compileSdkVersion 26    
buildToolsVersion '26.0.2'    
defaultConfig { 
   applicationId "com.your.packagename"  
   minSdkVersion 16
   targetSdkVersion 26
   versionCode 1
   versionName "1.0"
   testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

   // add below section
   javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }
 }
}

忘了提到我已经尝试过这个方法了。还有其他的解决方案吗? - Marian Pavel
此选项已被弃用,并将在未来删除。 请参阅https://developer.android.com/r/tools/annotation-processor-error-message.html 了解更多详情。 - Zon
无法工作。 - StarWind0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接