不构建核心库时不明智或错误地使用核心类(java.* 或 javax.*)
当我清理项目时,出现以下错误:
[2011-10-05 13:47:53 - The Basics] Dx
trouble processing "java/nio/CharBuffer.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
这通常是由于无意中包含核心库文件造成的 在您的应用程序项目中,当使用 IDE(例如 蚀)。如果您确定您不是有意定义 核心类,那么这是最有可能的解释 正在进行中。
然而,您实际上可能试图在核心中定义一个类 名称空间,您可能已获取其来源,例如, 来自非 Android 虚拟机项目。这将最 肯定不行。至少,它会危及 您的应用程序与平台未来版本的兼容性。 它的合法性也常常受到质疑。
如果你真的打算构建一个核心库——这只是 适合作为创建完整虚拟机的一部分 分发,而不是编译应用程序——然后使用 “--core-library”选项可以抑制此错误消息。
如果您继续使用“--core-library”,但实际上 构建一个应用程序,然后预先警告您的应用程序 在某些时候仍然无法构建或运行。请 为愤怒的客户做好准备,例如,他们发现您的 一旦升级操作,应用程序将停止运行 系统。你将要为这个问题负责。
如果您合法地使用恰好位于 core 包,那么你拥有的最简单安全的替代方案是 重新打包该代码。也就是说,将有问题的类移动到 你自己的包命名空间。这意味着他们永远不会在 与核心系统类冲突。 JarJar 是一个可能有帮助的工具 你在这一努力中。如果您发现自己无法做到这一点,那么 这表明你所走的道路最终将 导致痛苦、痛苦、悲伤和哀叹。
[2011-10-05 13:47:53 - The Basics] Dx 1 error; aborting
[2011-10-05 13:47:53 - The Basics] Conversion to Dalvik format failed with error 1
When I clean my project I get the following error:
[2011-10-05 13:47:53 - The Basics] Dx
trouble processing "java/nio/CharBuffer.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.
[2011-10-05 13:47:53 - The Basics] Dx 1 error; aborting
[2011-10-05 13:47:53 - The Basics] Conversion to Dalvik format failed with error 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了这个问题。我使用 Maven 来构建我的 Android 项目。我的问题是由我的依赖项之一引起的,具体取决于 android jars。我更新了我的 pom 以将 android 从该依赖项中排除,这为我解决了这个问题。
希望这对某人有帮助,我花了一段时间才弄清楚发生了什么事。
I had this problem. I use Maven to build my android projects. My problem was caused by one of my dependencies depending on the android jars. I updated my pom to exclude android from that dependency and that solved it for me.
Hope this helps someone, it took me a while to figure out what was going on.
为了让任何可能偶然发现此问题的人受益,此问题可能是由于包含较旧的库(例如
android.jar
)而引起的。从构建路径中删除.jar
文件将允许您进行编译。否则,您可以使用错误消息中提到的“jarjar”将.jar
文件移动到另一个包。For the benefit of anyone who may have stumbled upon this, this problem can be caused by inclusion of an older library such as
android.jar
. Removing the.jar
file from your buildpath will allow you to compile. Otherwise, you can use the "jarjar" mentioned in the error message to move the.jar
file to another package.您的 IDE 配置错误。确保您的脚本或 IDE 没有将
rt.jar
或android.jar
传递给dx
。Your IDE is misconfigured. Make sure that your scripts or IDE isn't passing
rt.jar
orandroid.jar
todx
.在 Android Studio 中,我在
lib
文件夹中包含了 java 和 javax jar 文件,并且存在与它们相关的依赖项(在应用程序级别的build.gradle
中)。我把它们注释掉了。然后我进入项目视图并删除了 jar 文件。有一些 java.awt.geom 的遗留实例,我必须清除它们,但重建项目,然后就没事了。
In Android Studio, I had included java and javax jar files in my
lib
folder and there were dependencies related to them (inbuild.gradle
at the app level). I commented them out.Then i went to the Project View and deleted the jar files. There were some legacy instances of java.awt.geom which I had to purge, but rebuilt project and then i was fine.