简体   繁体   中英

NoClassDefFoundError for custom annotation processor in Android Studio 3.0

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'

OK. Got it worked by stetting includeCompileClasspath to true in build.gradle .

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

    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM