【问题标题】:Conversion to Dalvik format failed with error 1 in Android 4?在 Android 4 中转换为 Dalvik 格式失败并出现错误 1?
【发布时间】:2011-11-03 16:26:44
【问题描述】:

在我的 Eclipse 中的 Android 应用程序中,我收到以下错误:

[2011-11-03 19:39:12 - MiniPauker 1.0] Dx 
trouble processing "java/crcis/pauker/AddCardActivity$1.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-11-03 19:39:12 - MiniPauker 1.0] Dx 1 error; aborting
[2011-11-03 19:39:12 - MiniPauker 1.0] Conversion to Dalvik format failed with error 1

此错误仅在运行我的项目时出现。我花了很长时间寻找正确的解决方案,但所有可能的解决方案都不起作用。我现在使用 android 4.0 和 Eclipse 3.6

顺便说一句,这个项目在 Android 2.1 中运行,但在 Android 4.0 中不行!!!

【问题讨论】:

    标签: android


    【解决方案1】:

    您的包名以 java 开头,它是为核心 Java 包保留的。如果可能的话,你应该重命名你的包。

    【讨论】:

    • 只是值得注意的是,如果它以 javax 开头,也会发生同样的事情
    【解决方案2】:

    我得到这个是因为我手动将 android.jar 添加到构建库中,因为它说它没有找到 android 库。解决办法是……

    1. 从构建库中移除 android.jar

    2. 右击项目,进入“Android工具”,选择“修复项目属性”

    希望这会有所帮助。

    【讨论】:

    • 谢谢,但我不知道从构建库中删除 android.jar。当我选择“修复项目属性”时,不要发生任何事情!
    • 如果您右键单击您的项目,然后转到“Java Build Path”,然后选择“Libraries”选项卡,应该包含 Android 库(不仅仅是“android.jar”)我做了手动添加“android.jar”的错误导致了这个问题。此视图应包括 Android / Google API 库(其中包括 jars)。希望这会有所帮助。
    • 在这种情况下,可能是您多次包含一个库/jar,不一定是 android.jar,而是另一个。我会先检查以确保不是这种情况。
    【解决方案3】:

    您必须检查您的项目(或依赖库)在构建路径(Project>Properties>Java Build Path>Order and Export)中不包含 android.jar

    如果您的主项目在 Android Private Libraries 中包含 android.jar,那么您必须检查添加到项目中的所有库的构建路径并删除 android.jar 来自构建路径。

    【讨论】:

      【解决方案4】:

      修改jar包的scope属性导致的错误,从compile->提供,这个操作可以在File->Project Structure->Dependencies中修改或者在项目视图app文件夹下build.gradle文件有dependencies,对应的jar包编译修改 像这样: enter image description here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-08
        • 2012-12-07
        • 2011-06-29
        相关资源
        最近更新 更多