體驗(yàn)最新版AndroidStudio3.0 的時(shí)候,發(fā)現(xiàn)之前項(xiàng)目的butter knife報(bào)錯(cuò),用到注解的應(yīng)該都會(huì)報(bào)錯(cuò)。報(bào)錯(cuò)提示如下:
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在錯(cuò)誤日志中有出現(xiàn),指的是在哪個(gè)項(xiàng)目或者庫中報(bào)錯(cuò)。找到那個(gè)項(xiàng)目,并修改其中的build.gradle文件。如果項(xiàng)目中存在多個(gè)項(xiàng)目相繼繼承的關(guān)系,可能存在會(huì)有多處這樣的報(bào)錯(cuò),應(yīng)該依次地把各個(gè)報(bào)錯(cuò)的項(xiàng)目的build.gradle文件按如下方法修改)

image.png
build.gradle:
apply plugin: 'com.android.application'
android {
...
defaultConfig {
...
//添加如下配置就OK了
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
}