设置显式注释处理器 [英] Setting Explict Annotation Processor

查看:29
本文介绍了设置显式注释处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Maven 存储库添加到我的 Android Studio 项目中.当我做一个 Gradle 项目同步时,一切都很好.但是,每当我尝试构建我的 apk 时,我都会收到此错误:

I am attempting to add a maven repository to my Android Studio project. When I do a Gradle project sync everything is fine. However, whenever I try to build my apk, I get this 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.
 - 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.

包含的链接(https://developer.android.com/r/tools/annotation-processor-error-message.html) 在错误 404s 中,所以它没有帮助.

The link included (https://developer.android.com/r/tools/annotation-processor-error-message.html) in the error 404s so its of no help.

我在 android studio 设置中启用了注释处理,并将 includeCompileClasspath = true 添加到我的注释处理器选项中.我还尝试将 classindexclassindex-3.3classindex-3.3.jar 添加到处理器 FQ 名称,但这也无济于事.

I have enabled annotation processing in the android studio settings, and added includeCompileClasspath = true to my Annotation Processor options. I have also tried adding classindex, classindex-3.3 and classindex-3.3.jar to Processor FQ Name, but that did not help either.

这些是我添加到依赖项下默认 build.gradle 的行:

these are the lines I have added to the default build.gradle under dependecies:

dependencies {
    ...
    compile group: 'com.skadistats', name: 'clarity', version:'2.1.1'
    compile group: 'org.atteo.classindex', name: 'classindex', version:'3.3'
}

最初我只是添加了清晰度",因为这是我关心的,但我添加了classindex"条目,希望它能修复它.删除清晰度"并保留classindex"给了我完全相同的错误.

Originally I just had the "clarity" one added, because that is the one I care about, but I added the "classindex" entry in the hopes that it would fix it. Removing "clarity" and keeping "classindex" gives me the exact same error.

我对 gradle/maven 不太熟悉,所以任何帮助将不胜感激.

I'm not all too familiar with gradle/maven so any help would be appreciated.

推荐答案

要修复错误,只需更改这些依赖项的配置以使用 annotationProcessor.如果依赖项包括也需要在编译类路径上的组件,请再次声明该依赖项并使用编译依赖项配置.

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.

例如:

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

此链接详细介绍:https://developer.android.com/studio/preview/features/new-android-plugin-migration.html#annotationProcessor_config

包含相关代码片段以确保完整性.

Relevant snippet included for completeness.

使用注解处理器依赖配置

Use the annotation processor dependency configuration

在以前版本的 Gradle 的 Android 插件中,依赖于编译类路径被自动添加到处理器类路径.也就是说,您可以向编译类路径,它会按预期工作.然而,这导致通过添加大量对性能产生显着影响对处理器的不必要依赖.

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.

使用新插件时,注解处理器必须添加到使用 annotationProcessor 依赖项的处理器类路径配置,如下图:

When using the new plugin, annotation processors must be added to the processor classpath using the annotationProcessor dependency configuration, as shown below:

依赖项{...annotationProcessor 'com.google.dagger:dagger-compiler:' }

dependencies { ... annotationProcessor 'com.google.dagger:dagger-compiler:' }

插件假定依赖项是一个注解处理器,如果它的 JAR文件包含以下文件:META-INF/services/javax.annotation.processing.Processor.如果插件在编译类路径上检测注释处理器,您的构建失败,您会收到一条错误消息,其中列出了每个注释编译类路径上的处理器.要修复错误,只需更改这些依赖项的配置使用 annotationProcessor.如果依赖项包括也需要在编译中的组件类路径,再次声明该依赖项并使用编译依赖配置.

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.

这篇关于设置显式注释处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆