Android Studio 3.0 Annotation processors Error

升级到Android Studio 3.0之后,当编译项目的时候,如果项目使饮用了Lombok和Butterknifeh这两个开源项目,你就会发现在编译过程中发生以下错误:

1
2
3
4
5
Error:Execution failed for task ':Base: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.

错误日志已经告诉我们了,在Android Studio 3.0 之后 annotationProcessor必须由我们开发者显示声明了,添加annotationProcessor之后即可解决此问题。

1
2
compile 'com.jakewharton:butterknife:7.0.1'
annotationProcessor 'com.jakewharton:butterknife:7.0.1'

参考链接:

分享到