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

时间:2017-05-20 09:36:10

标签: android android-studio android-gradle

刚升级到Android Studio 3.0,之前正在编译的项目会抛出以下错误

  

错误:java.lang.RuntimeException:现在必须是注释处理器   明确宣布。编译中的以下依赖项   发现classpath包含注释处理器。请添加它们   到annotationProcessor配置。

但是,此following未定义。这是我的build.gradle中的compile语句如何看起来像

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 个答案:

答案 0 :(得分:22)

结果LombokButterknife导致问题

我更新了ButterKnife并为Lombok添加了一个解决问题的注释处理器

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更改为implementationprovided更改为compileOnly

答案 1 :(得分:13)

编译后看错误信息。它将显示需要注释过程的包名称。例如:

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
}

答案 2 :(得分:4)

  1. 打开项目的build.gradle
  2. 只需在defaultConfig中添加以下行:

     javaCompileOptions {
                    annotationProcessorOptions {
                          includeCompileClasspath true
                      }
                 }
    

答案 3 :(得分:1)

我对MPchart库有同样的问题,在MPchart项目的 build.gradle 中添加:

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

答案 4 :(得分:0)

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

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

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

答案 5 :(得分:0)

确保您在app gradle文件中使用:

annotationProcessor 

而不是

implementationcompile

它更容易,更快,

e.g。

dependencies {

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

}