Android Studio 3.0 Canary 1 annotation processor error-ThrowExceptions

Exception or error:

Just upgraded to Android Studio 3.0, a project which was compiling before is throwing following error

Error:java.lang.RuntimeException: Annotation processors must now be
declared explicitly. The following dependencies in the compile
classpath are found to contain annotation processors. Please add them
to the annotationProcessor configuration.

However, this following is not defined. here is how compile statements in my build.gradle looks like

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'
How to solve:

Turns out Lombok and Butterknife were causing issues

I updated ButterKnife and added annotationProcessor for Lombok which solved the issue

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"

Update

As per @Beshoy’s comment below changed compile to implementation and provided to compileOnly

###

see the error message after compiling. it will show the package name which need Annotation process. for example:

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.

search name “realm-android-0.87.5” in build.gradle file of Module “MPChart_libary”:

dependencies {
    provided 'io.realm:realm-android:0.87.5' 
}

fix build.gradle file as following:

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

###

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

     javaCompileOptions {
                    annotationProcessorOptions {
                          includeCompileClasspath true
                      }
                 }
    

###

I have same problem with MPchart library, in build.gradle of MPchart project add this:

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

###

Make sure that in your app gradle file you use:

annotationProcessor 

instead of

implementation or compile

It’s easier and faster,

e.g.

dependencies {

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

}

###

1- Disable the annotation processor error check

If you have dependencies on the compile classpath that include annotation processors you don’t need, you can disable the error check by adding the following to your build.gradle file. Keep in mind, the annotation processors you add to the compile classpath are still not added to the processor classpath.

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

Leave a Reply

Your email address will not be published. Required fields are marked *