Setting Explict Annotation Processor

半世苍凉 提交于 2019-12-02 14:49:49

To fix the error, simply change the configuration of those dependencies to use annotationProcessor. If a dependency includes components that also need to be on the compile classpath, declare that dependency a second time and use the compile dependency configuration.

For example:

annotationProcessor 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton:butterknife:7.0.1'

This link describes it in detail: https://developer.android.com/studio/preview/features/new-android-plugin-migration.html#annotationProcessor_config

Relevant snippet included for completeness.

Use the annotation processor dependency configuration

In previous versions of the Android plugin for Gradle, dependencies on the compile classpath were automatically added to the processor classpath. That is, you could add an annotation processor to the compile classpath and it would work as expected. However, this causes a significant impact to performance by adding a large number of unnecessary dependencies to the processor.

When using the new plugin, annotation processors must be added to the processor classpath using the annotationProcessor dependency configuration, as shown below:

dependencies { ... annotationProcessor 'com.google.dagger:dagger-compiler:' }

The plugin assumes a dependency is an annotation processor if its JAR file contains the following file: META- INF/services/javax.annotation.processing.Processor. If the plugin detects annotation processors on the compile classpath, your build fails and you get an error message that lists each annotation processor on the compile classpath. To fix the error, simply change the configuration of those dependencies to use annotationProcessor. If a dependency includes components that also need to be on the compile classpath, declare that dependency a second time and use the compile dependency configuration.

I was with a similar error. I follow the instructions on the Google link and it works.

try to add the follow instructions to your app gradle file:

defaultConfig {
    applicationId "com.yourdomain.yourapp"
    minSdkVersion 17
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"

    javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath false
        }
    }
}

Attention to -> includeCompileClasspath false

Amirouche Zeggagh

Add this code to your gradle app

defaultConfig{
    javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }
}

I found the solution here https://github.com/JakeWharton/butterknife/issues/908

Simply update your butter knife with Annotation processor

compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

i hope it's help you

Tushar Ahmed

Add this in defaultConfig

android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true

In the build.gradle(module app)

  1. apply the plugin:

     apply plugin: 'com.jakewharton.butterknife'
    
  2. Add the following lines in the dependencies section:

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

in the build.gradle(Project:projectName), add the classPath in the dependencies like this :

    classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'

It will fix this issue. In case if not then add maven:

 maven {
 url 'https://maven.google.com'
 }

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 {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
    }
}

If you are experiencing issues migrating to the new dependency resolution strategy, you can restore behavior to that of Android plugin 2.3.0 by setting includeCompileClasspath true. However, restoring behavior to version 2.3.0 is not recommended, and the option to do so will be removed in a future update.

See here https://developer.android.com/r/tools/annotation-processor-error-message.html for more details

If nothing works from above answers add following step as well, specially for new update of Android Studio 3.0.1:

Android Studio 3.0.1:

Add this to your app.gradle file in dependencies:

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

In previous versions of the plugin, dependencies on the compile classpath were automatically added to the processor classpath. That is, you could add an annotation processor to the compile classpath and it would work as expected. However, this causes a significant impact to performance by adding a large number of unnecessary dependencies to the processor.

When using the Android plugin 3.0.0, you must add annotation processors to the processor classpath using the annotationProcessor dependency configuration, as shown below:

dependencies { ... annotationProcessor 'com.google.dagger:dagger-compiler:<version-number>' implementation 'com.google.dagger:dagger-compiler:<version-number>' }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!