Android Studio 3中解决androidannotations报错

Android Studio 3中解决androidannotations报错

报错

最近Fork了一个项目,报以下错误

1
2
3
4
5
Error:Execution failed for task ':sample: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.
- androidannotations-4.0.0.jar (org.androidannotations:androidannotations:4.0.0)
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.

解决方法

在app目录下的gradle文件中添加

{
1
2
3
4
    annotationProcessorOptions {
includeCompileClasspath = true
}
}

变为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
android {
compileSdkVersion 25
buildToolsVersion "26.0.2"

defaultConfig {
minSdkVersion 11
targetSdkVersion 25
versionCode 3
versionName "3.0.0"

javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true
}
}
}

}
Fork me on GitHub