当前位置: 首页 > 知识库问答 >
问题:

设置显式注释处理器

金伟
2023-03-14
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添加到我的注释处理器选项中。我还尝试将classindexclassindex-3.3classindex-3.3.jar添加到处理器FQ名称中,但这也没有帮助。

这些是我添加到dependecies下的默认build.gradle中的行:

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”会给我带来完全相同的错误。

我对Gradle/Maven不是很熟悉,所以如果有任何帮助,我将不胜感激。

共有1个答案

梅玉堂
2023-03-14

要修复该错误,只需更改这些依赖项的配置以使用AnnotationProcessor。如果依赖项包括也需要在compile类路径上的组件,则第二次声明该依赖项并使用compile依赖项配置。

例如:

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

在以前版本的Android Gradle插件中,对编译类路径的依赖被自动添加到处理器类路径中。也就是说,您可以向compile类路径添加一个注释处理器,它将按预期工作。但是,这会给处理器添加大量不必要的依赖项,从而对性能造成重大影响。

在使用新插件时,必须使用annotationProcessor依赖项配置将注释处理器添加到处理器类路径中,如下所示:

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

 类似资料:
  • 我看到了这个问题,但问题是auto-value-1.1.jar不在我的gradle文件中

  • 我在我的Android中添加了以下库,然后我得到了错误。 https://github.com/bumptech/glide/releases/download/v4.6.1/compiler-4.6.1.jar https://github.com/bumptech/glide/releases/download/v4.6.1/glide-full-4.6.1.jar 错误: 等级:

  • 我正在尝试开发一个Kotlin AnnotationProcessor库,我想不出为什么会出现这个错误: 错误:任务“:app:javaprecompiledebug”执行失败。 >现在必须显式声明批注处理器。发现编译类路径上的以下依赖项包含注释处理器。请将它们添加到annotationProcessor配置中。  · · · -compiler.jar(项目:编译器)  · 或者,设置andro

  • 我正在使用EclipseIndigo,有一个Maven项目,它使用注释处理器生成代码。 我已经在项目属性中设置了注释处理(在Eclipse中),但理想情况下,我更希望这个IDE设置由Maven管理,这样我就可以轻松地与同事共享它。 如有任何建议,将不胜感激

  • 突然,我在执行应用程序时出错。我知道这里已经有人问过这个问题:现在必须显式声明注释处理器 然而,解决方案并没有解决问题:( 这是我的build.gradle 任何人都知道如何解决这个错误。我在谷歌上搜索没有成功。 这是收到的错误

  • 问题内容: 在阅读 Java 中的自定义注释处理器的代码时,我注意到处理器方法中的这段代码: 碰巧我也在使用自定义注释处理器,所以我想在我的注释处理器中使用上面的代码段。 我以这种方式尝试了上面的代码: & 这条路: 但我没有注意到处理器行为的任何变化。我得到了支票,但看不到有什么用。 我想知道在处理特定回合时有用的用例。 问题答案: 这两项检查都很重要,但是直到在同一项目中一次运行多个注释处理器