【Android】編譯報錯 Annotation processors must be explicitly declared now 解決方案


問題

在網上下載一個demo,因為版本久遠,里面添加了本地 Butter Knife 的jar包,在編譯時報錯 

  

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 (butterknife-7.0.1.jar) 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.

 

看提示應該是找不到包,項目配置的問題

按照dependencies中增加annotationProcessor 依賴內容的方法並沒有成功

 

 

 

解決方法

在 app 的 build.gradle 文件中添加 includeCompileClasspath 參數:

apply plugin: 'com.android.application'

android {
    ···

    defaultConfig {
    ···
        // 顯式聲明支持注解
        javaCompileOptions{
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }
    }
    
}

dependencies {
    ···
implementation files('libs/butterknife-7.0.1.jar')

    ···
}

重新 build 一下

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM