体验最新版AndroidStudio3.0 的时候,发现之前项目的butter knife报错,用到注解的应该都会报错。报错提示如下:
Error:Execution failed for task ':common: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.
- butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1)
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.
解决方法:
在project/common/build.gradle的android{defaultConfig{}}中添加:
(注意:这里的common在错误日志中有出现,指的是在哪个项目或者库中报错。找到那个项目,并修改其中的build.gradle文件。如果项目中存在多个项目相继继承的关系,可能存在会有多处这样的报错,应该依次地把各个报错的项目的build.gradle文件按如下方法修改)
build.gradle:
apply plugin: 'com.android.application'
android {
...
defaultConfig {
...
//添加如下配置就OK了
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
}