Android Studio 3.0 Canary 1注解处理器错误

19

刚刚升级到Android Studio 3.0,之前可以编译的项目出现了以下错误:

Error:java.lang.RuntimeException: 注释处理器现在必须明确定义。在编译类路径中发现以下依赖项包含注释处理器,请将它们添加到annotationProcessor配置中。

然而,这个“following”未被定义。这是我的build.gradle中编译声明的样子。

compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
    transitive = true;
}

compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.jakewharton.timber:timber:4.4.0'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'io.reactivex:rxjava:1.0.14'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.jpardogo.googleprogressbar:library:1.2.0'
compile 'com.wang.avi:library:2.1.3'
compile 'link.fls:swipestack:0.3.0'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.codemybrainsout.rating:ratingdialog:1.0.7'
compile 'org.greenrobot:greendao:3.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
provided 'org.projectlombok:lombok:1.12.6'
6个回答

22

事实证明,LombokButterknife引起了问题

我更新了ButterKnife,并为Lombok添加了annotationProcessor,这解决了问题

implementation 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'

compileOnly 'org.glassfish:javax.annotation:10.0-b28'
compileOnly "org.projectlombok:lombok:1.16.16"
annotationProcessor "org.projectlombok:lombok:1.16.16"

更新

根据 @Beshoy 在下面的评论中,将 compile 更改为 implementation,将 provided 更改为 compileOnly


1
你还应该更新你的依赖配置。compileprovided 已经被弃用,使用 implementationcompileOnly。https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations - Beshoy Fayez
非常重要的是 lombok 的 'compileOnly'。只使用 'compile' 对我来说无法正常工作。 - galaxigirl
所有这些是什么意思?为什么它一直在变化?它似乎有点复杂,只是我自己的问题吗? - Sreekanth Karumanaghat
@SreekanthKarumanaghat,它第一次发生了变化。AnnotationProcessors被用来在代码编译之前处理注释,例如@NonNull - Abhishek Bansal

14

编译后查看错误信息,会显示需要注释处理的包名。例如:

Error:Execution failed for task ':MPChart_libary:javaPreCompileDebug'.
> Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
    - realm-android-0.87.5.jar
  Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
  See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

在“MPChart_libary”模块的build.gradle文件中搜索名称为“realm-android-0.87.5”的内容:
dependencies {
    provided 'io.realm:realm-android:0.87.5' 
}

将build.gradle文件修复为以下内容:

dependencies {
    provided 'io.realm:realm-android:0.87.5' 
    annotationProcessor 'io.realm:realm-android:0.87.5' //fix here
}

4
  1. Open build.gradle of project
  2. Just add these line in defaultConfig :

     javaCompileOptions {
                    annotationProcessorOptions {
                          includeCompileClasspath true
                      }
                 }
    

1
请确保在您的应用 gradle 文件中使用以下内容:
annotationProcessor 

替代

实现编译

更加简单快捷,

例如:

dependencies {

    //BUTTERKNIFE
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

}

1

我和MPchart库遇到了同样的问题,在MPchart项目的build.gradle文件中添加以下内容:

defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }
    }

0

1- 禁用注释处理器错误检查

如果您在编译类路径上有依赖项,其中包括您不需要的注释处理器,则可以通过将以下内容添加到 build.gradle 文件来禁用错误检查。请注意,您添加到编译类路径的注释处理器仍未添加到处理器类路径中。

android {
    ... //others options
    defaultConfig {
    ...
    javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath false
        }
      }
   }
}

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