Setting Explict Annotation Processor
Asked Answered
I

9

63

I am attempting to add a maven repository to my Android Studio project. When I do a Gradle project sync everything is fine. However, whenever I try to build my apk, I get this error:

Execution failed for task ':app: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.
 - classindex-3.3.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.

The link included (https://developer.android.com/r/tools/annotation-processor-error-message.html) in the error 404s so its of no help.

I have enabled annotation processing in the android studio settings, and added includeCompileClasspath = true to my Annotation Processor options. I have also tried adding classindex, classindex-3.3 and classindex-3.3.jar to Processor FQ Name, but that did not help either.

these are the lines I have added to the default build.gradle under dependecies:

dependencies {
    ...
    compile group: 'com.skadistats', name: 'clarity', version:'2.1.1'
    compile group: 'org.atteo.classindex', name: 'classindex', version:'3.3'
}

Originally I just had the "clarity" one added, because that is the one I care about, but I added the "classindex" entry in the hopes that it would fix it. Removing "clarity" and keeping "classindex" gives me the exact same error.

I'm not all too familiar with gradle/maven so any help would be appreciated.

Innumerable answered 24/3, 2017 at 7:17 Comment(1)
readyandroid.wordpress.com/…Cran
F
87

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.

Fossiliferous answered 31/5, 2017 at 20:26 Comment(0)
F
37

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

Farouche answered 30/4, 2017 at 1:58 Comment(4)
"Note that this option is deprecated and will be removed in the future."Claudeclaudel
Yes @everyman, but for now it's the option we have to handle this.Farouche
Recommended not to use this approach. Please refer this answer instead. https://mcmap.net/q/301661/-setting-explict-annotation-processorNucleoside
It works for me, and it must be added in the build.gradle of app module not your lib module, if your annotationProcessor put in the build.gradle lib module.Fanchon
E
23

Add this code to your gradle app

defaultConfig{
    javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }
}

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

Eisenberg answered 28/8, 2017 at 14:31 Comment(0)
M
11

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

Magnetomotive answered 1/11, 2017 at 7:27 Comment(0)
S
4

Add this in defaultConfig

android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true

Sedulous answered 22/5, 2018 at 17:55 Comment(1)
This option is deprecated and will be removed in the future.Humbertohumble
B
2

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'
 }
Blown answered 14/3, 2018 at 15:12 Comment(0)
B
1

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

Bybee answered 28/11, 2017 at 8:22 Comment(0)
G
0

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'
Graniteware answered 12/2, 2018 at 7:49 Comment(0)
P
0

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>' }

Pelt answered 11/7, 2018 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.