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

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

问题描述

我正在尝试将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 )中的错误404,因此毫无帮助.

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添加到了注释处理器"选项中.我也尝试过在处理器FQ名称中添加classindexclassindex-3.3classindex-3.3.jar,但这也无济于事.

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'
}

最初,我只是添加了"clarity",因为这是我关心的问题,但是我添加了"classindex"条目,希望它可以解决该问题.删除"clarity"并保留"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.

推荐答案

要解决该错误,只需将这些依赖项的配置更改为使用注释处理器即可.如果依赖项包含也需要在编译类路径上的组件,请再次声明该依赖项,然后使用编译依赖项配置.

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

This link describes it in detail: 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插件的早期版本中,对 编译类路径自动添加到处理器 类路径.也就是说,您可以将注释处理器添加到 编译classpath,它将按预期工作.但是,这导致 通过添加大量 对处理器的不必要依赖.

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:

依赖项{ ... 注解处理器'com.google.dagger:dagger-compiler:'}

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

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

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天全站免登陆