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.
Annotation processing is a tool built into javac for scanning and processing annotations at compile time. It can create new source files; however, it can't modify existing ones. It's done in rounds. The first round starts when the compilation reaches the pre-compile phase.
An annotation processor is a class which extends AbstractProcessor (in the package javax. annotation. processing ) providing the functionality needed to generate whatever it needs to generate, such as classes in the case of mapstruct.
An annotation processor is a plug-in to the Java compiler itself. So in order to debug a processor it either needs to run inside the compiler itself or be provided with a mock Compiler API. The Compiler API is rather complex and extensive to mocking it, even using mocking libraries such as Mockito, is not viable.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With