Android Studio中注解处理器(annotation processors)的增量编译失败分析

📅 2026/7/22 15:43:42
Android Studio中注解处理器(annotation processors)的增量编译失败分析
导入第三方aar库后编译出现如下异常 Task :app:compileK4t3ReleaseJavaWithJavac FAILED Gradle may disable incremental compilation as the following annotation processors are not incremental: realm-annotations-processor-3.0.0.jar (io.realm:realm-annotations-processor:3.0.0), butterknife-compiler-8.8.1.jar (com.jakewharton:butterknife-compiler:8.8.1), classes.jar (******.aar). Consider setting the experimental feature flag android.enableSeparateAnnotationProcessingtrue in the gradle.properties file to run annotation processing in a separate task and make compilation incremental. Execution failed for task :app:compileK4t3ReleaseJavaWithJavac. Invalid signature file digest for Manifest main attributes根据提示是由于gradle不支持注解处理器的增量编译导致的编译失败根据提示可在gradle.properties中加入android.enableSeparateAnnotationProcessingtrue设置来解决增量编译功能是与 Gradle 4.10.1 及更高版本兼容的但由于 Gradle问题与 Gradle 5.1 并不兼容故在gradle5.1.1版本中不能通过添加android.enableSeparateAnnotationProcessingtrue设置来解决该编译失败问题。