Home » Java » NoClassDefFoundError for custom annotation processor in Android Studio 3.0

NoClassDefFoundError for custom annotation processor in Android Studio 3.0

Posted by: admin October 26, 2017 Leave a comment

Questions:

I have a custom annotation processor which parses XML files. It was working fine with Android Studio 2.3.3, now I have updated Android Studio to version 3.0(Stable), it suddenly started throwing NoClassDefFound error for the annotation of my annotation processor.

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.NoClassDefFoundError: io/github/***/annotations/****

In Gradle

   compile  'io.github.allaudin:****:1.0.0'
   annotationProcessor  'io.github.allaudin:****-processor:1.0.0'
Answers:

You must migrate to the new android gradle plugin: follow these steps

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