1. 程式人生 > >android Studio 3.0 後使用 butterknife 問題

android Studio 3.0 後使用 butterknife 問題

版權宣告:本文為博主原創文章,未經博主允許不得轉載。https://mp.csdn.net/postedit/81507137

butterknife:7.0.1'  使用

 

體驗最新版AndroidStudio3.0 Canary 8的時候,發現之前專案的butterknife報錯,
Error:Execution failed for task ':app: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
  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.

在自己專案的build.gralde 裡面新增

在app的build中
android {
    ...
    defaultConfig {
        ...
        //新增如下配置就OK了
        javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
    }
    ...
}

butterknife:8.8.1'  使用

 

implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
android {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath = true  
            }
        }
    }
}