java - Android 应用程序中无法包含 "javaee-api-7.0.jar"

标签 java android jakarta-ee

当我尝试运行 Android 应用程序并将“javaee-api-7.0.jar”包含在我的 libs 文件夹中时,我在编译时收到以下错误:

[2014-04-22 11:27:53 - firstApp] Dx 
trouble processing "javax/management/j2ee/ListenerRegistration.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.

If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.

[2014-04-22 11:27:53 - firstApp] Dx 1 error; aborting
[2014-04-22 11:27:53 - firstApp] Conversion to Dalvik format failed with error 1

如何修复此错误?

最佳答案

看起来javax.management.*current set of APIs offered by the Android platform中不可用。这意味着暂时抑制警告是安全的。但如果 Android 决定添加这个类,就会有麻烦。

但是,就我而言,需要 javaee-api 但似乎并未实际使用,因此我可以按如下方式抑制此依赖性(语法取自 here ):

    compile("io.grpc:grpc-all:0.7.1") {
      exclude group: "javax"
    }

如果您确实需要 javaee-api 包中的某些内容,则应使用 JarJar 对其进行重命名,如错误消息所示。 jarjar-gradle插件在这里会很有用。

关于java - Android 应用程序中无法包含 "javaee-api-7.0.jar",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23211625/

相关文章:

java - 重新启动 Java 游戏

java - JPA/hibernate : schema generation with multiple persistence units

java - PreparedStatement 有什么问题?

android - 在根项目 'android' React Native 中找不到“installDebug”

java - servlet 以编程方式设置身份验证

java - WAR 文件的烦人的 Tomcat 问题

java - Jsoup 将我的 javascript 字符串转换为一行

android - 如何预览自定义字体 Android Studio(使用书法)

java - 拦截器无法访问操作参数

java - 在 servlet 中运行多线程