android - 将 Jar 导入 Android 项目时出错

标签 android dex

这是新的 Android SDK 最近出现的问题。

现在 Android SDK 在将外部 jar 导入 apk 包时使用 ANT 约定,外部 jar 必须位于“lib”文件夹中,并且 SDK 会从该文件夹中导出 jar。

我的问题是当我添加我的 jars 并运行我的项目时我收到这条消息:

trouble processing "javax/transaction/HeuristicCommitException.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.

我在此处和其他论坛上看到了这条消息,有些人说 Android.jar 是问题所在,所以删除即可解决。

但我找不到那个 Android.jar,除了无法删除的 Android 库。

这个关于将库导入 android 的问题让我很生气,因为我的应用程序运行得非常好。

最佳答案

我在第一次更新时也看到了很多问题,但最终能够让它正常工作。基于最终对我和 friend 有用的一些建议:

确保您的外部 jar 位于项目基目录的“libs”文件夹中(注意此处的“s”——而不是“lib”)。如果您进行任何更改,请务必刷新项目并清理(如果未设置为自动构建,则重新构建)。

在 Java Build Path > Libraries 选项卡下的项目属性中,删除除 Android X.X.X 和 Android Dependencies 节点之外的所有内容。同样,如果您进行了任何更改,请务必刷新项目并清理(如果未设置为自动构建,则重新构建)。

如果您已为您的项目及其在您的工作区中使用的所有库项目完成此操作但仍然遇到问题,请尝试删除所有 Android 库项目(从项目属性 > Android)以及 Java 构建路径中的所有库(这次包括 Android X.X.X 和 Android 依赖),清理,然后更改 Android 版本/应用/改回以强制重建。 (对从您的基础库项目开始的每个项目执行此操作,只有在它们构建无误后才将它们添加到您的其他项目中)。

希望对您有所帮助。

关于android - 将 Jar 导入 Android 项目时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10157213/

相关文章:

java - 自动启动和停止方法

android - 如何在 Kotlin Gradle dsl 中使用 Firebase BoM?

java - Android 数组列表添加值后返回 Null

java - 如何将 Handler 与 CaptureSession.stopReapeating() 一起使用?

android - 动态加载 aar 库

android - 顶级异常应用程序 :dexDebug --dex -no-optimize --output android studio

java - 奇怪的错误转换为 dex 失败

java - Android dex 问题 : nested class + final boolean : com. android.dex.util.ExceptionWithContext

android - 生成apk文件时报错 "No DEX File Found"

android - 使用 2 个显示器的通用图像加载器