我正在尝试将 maven 存储库添加到我的 Android Studio 项目中。 当我进行 Gradle 项目同步时,一切都很好。但是,每当我尝试构建我的 apk 时,都会收到此错误:
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.
- classindex-3.3.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.
错误 404s 中包含的链接 (https://developer.android.com/r/tools/annotation-processor-error-message.html) 因此没有帮助。
我已在 android studio 设置中启用注释处理,并将 includeCompileClasspath = true
添加到我的注释处理器选项中。我还尝试将 classindex
、classindex-3.3
和 classindex-3.3.jar
添加到处理器 FQ 名称,但这也没有帮助。
这些是我在依赖项下添加到默认 build.gradle 的行:
dependencies {
...
compile group: 'com.skadistats', name: 'clarity', version:'2.1.1'
compile group: 'org.atteo.classindex', name: 'classindex', version:'3.3'
}
最初我只是添加了“清晰”项,因为这是我关心的一项,但我添加了“classindex”条目,希望它能修复它。删除“清晰度”并保留“classindex”给了我完全相同的错误。
我对 gradle/maven 不太熟悉,因此我们将不胜感激。
最佳答案
要修复错误,只需将这些依赖项的配置更改为使用 annotationProcessor。如果依赖项包含的组件也需要在编译类路径中,请再次声明该依赖项并使用编译依赖项配置。
例如:
annotationProcessor 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton:butterknife:7.0.1'
为了完整起见,包含相关 fragment 。
Use the annotation processor dependency configuration
In previous versions of the Android plugin for Gradle, dependencies on the compile classpath were automatically added to the processor classpath. That is, you could add an annotation processor to the compile classpath and it would work as expected. However, this causes a significant impact to performance by adding a large number of unnecessary dependencies to the processor.
When using the new plugin, annotation processors must be added to the processor classpath using the annotationProcessor dependency configuration, as shown below:
dependencies { ... annotationProcessor 'com.google.dagger:dagger-compiler:' }
The plugin assumes a dependency is an annotation processor if its JAR file contains the following file: META- INF/services/javax.annotation.processing.Processor. If the plugin detects annotation processors on the compile classpath, your build fails and you get an error message that lists each annotation processor on the compile classpath. To fix the error, simply change the configuration of those dependencies to use annotationProcessor. If a dependency includes components that also need to be on the compile classpath, declare that dependency a second time and use the compile dependency configuration.
关于android - 设置显式注释处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42993587/