AndroidStudio3.0 注解報(bào)錯(cuò)Annotation processors must be explicitly declared now.

體驗(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
            }
        }
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容