29

我想根据以下链接中的示例进行一些注释处理:http ://www.zdnetasia.com/writing-and-processing-custom-annotations-part-3-39362483.htm 。

但是,我想在我的 Android 项目中实现这个,似乎我不能在 android 平台上使用这个包。我需要添加一个外部 jar 还是缺少一些东西?

谢谢。

4

8 回答 8

23

Android 中不包含 javax.annotation.processing 包。您无需将其包含在已编译的应用程序模块中。在构建期间,您只需要编译器/处理器模块的这种依赖关系。因此,在您的应用程序中,build.gradle您应该在包含注释处理器后添加以下内容:

provided 'org.glassfish:javax.annotation:10.0-b28'
于 2015-07-07T15:10:21.823 回答
18

如果您使用 Android Studio / Gradle,有一个更简单的方法。

通过问题的答案,我发现以下内容如何将 javax.annotation.Generated 添加到 Java SE 5?

对于 Gradle 构建,依赖项应该是

compile 'org.glassfish:javax.annotation:10.0-b28'

于 2014-11-02T20:15:57.320 回答
11

javax.annotation.processing包不包含在 Android 中,但 Android VM 团队描述了如何在此处javax包含额外的包- 它可能适用于您的问题。

于 2012-03-10T22:45:46.720 回答
6
implementation 'org.glassfish:javax.annotation:10.0-b28'
compileOnly 'com.github.pengrad:jdk9-deps:1.0'

在您的文件中添加这两个依赖build.gradle项,这将起作用。

于 2021-07-02T08:25:04.093 回答
3

compileOnly 'org.glassfish:javax.annotation:10.0-b28'

于 2018-04-13T09:40:33.800 回答
2

只需添加 compile 'javax.annotation:javax.annotation-api:1.2' 就可以了。

查看所有可用版本:https ://mvnrepository.com/artifact/javax.annotation/javax.annotation-api

于 2016-03-31T12:41:54.003 回答
2

对于kotlin DSL,您需要使用compileOnly("org.glassfish:javax.annotation:10.0-b28")

对于groovy DSL,您需要使用compileOnly 'org.glassfish:javax.annotation:10.0-b28'

于 2020-06-08T12:04:20.073 回答
-4

我在黄油刀中找到了一种方法。将其添加到build.gradle

compile files(org.gradle.internal.jvm.Jvm.current().getJre().homeDir.getAbsolutePath()+'/lib/rt.jar')
于 2017-03-30T07:15:33.917 回答