Android Studio 3.0 中自定义注释处理器的 NoClassDefFoundError

NoClassDefFoundError for custom annotation processor in Android Studio 3.0

我有一个解析 XML 文件的自定义注释处理器。它在 Android Studio 2.3.3 上运行良好,现在我已经更新了 Android Studio to version 3.0(稳定),它突然开始为我的注释处理器的注释抛出 NoClassDefFound 错误。

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

在Gradle

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

您必须迁移到新的 android gradle 插件:关注 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>'
}

好的。通过在 build.gradle.

中设置 includeCompileClasspathtrue 来实现它
android {
    ...
    defaultConfig {
       ...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }

    }
}