java Android Dx Error1, 无法转换为 Dalvik 格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11537975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 05:29:53  来源:igfitidea点击:

Android Dx Error1, Failed to convert to Dalvik format

javaandroiddalvik

提问by billdoor

I'm getting desperate with this Problem: I want to export/run my Android Application with one additional .jarI added to the buildpath. I'm sure I added it correctly, there are 5 other .jars included and they all work fine.

我对这个问题感到绝望:我想导出/运行我的 Android 应用程序,.jar并在构建路径中添加一个额外的应用程序。我确定我添加正确,还包括 5 个其他 .jar,它们都可以正常工作。

with this special one I get the mentioned error. I've already tried everything that can be found in this question: "Conversion to Dalvik format failed with error 1" on external JAR

有了这个特殊的,我得到了提到的错误。我已经尝试了可以​​在这个问题中找到的所有内容: “Conversion to Dalvik format failed with error 1” on external JAR

and several other links google spat out. The main Problem is, I actually do not understand what the message I appended want's to tell me because if I add all the jars to a "normal" javaproject, it runs perfectly fine...

和谷歌吐出的其他几个链接。主要问题是,我实际上不明白我附加的消息想要告诉我什么,因为如果我将所有 jars 添加到“普通”javaproject,它运行得非常好......

Developing on Android 4.0.3,

proguard 4.8,

adt 16.0.1.v201112150204-238534,

eclipse 3.7.1.r37

在 Android 4.0.3 上开发,

Proguard 4.8,

广告 16.0.1.v201112150204-238534,

日食 3.7.1.r37

please help me

请帮我

[2012-07-18 10:45:48 - myapp] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class (iaik.xml.crypto.XSecProvider$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is notan inner class.

... ...

[2012-07-18 10:45:48 - myapp] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class (iaik.xml.crypto.XSecProvider$2) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is notan inner 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.

[2012-07-18 10:45:48 - myapp] Dx 1 error; aborting

[2012-07-18 10:45:48 - myapp] Conversion to Dalvik format failed with error 1

[2012-07-18 10:45:48 - myapp] Dx 警告:忽略匿名内部类 (iaik.xml.crypto.XSecProvider$1) 的 InnerClasses 属性,该属性不带有关联的 EnclosureMethod 属性。此类可能是由未针对现代 .class 文件格式的编译器生成的。推荐的解决方案是从源代码重新编译类,使用最新的编译器并且不指定任何“-target”类型选项。忽略这个警告的后果是对这个类的反射操作会错误地表明它不是一个内部类。

……

[2012-07-18 10:45:48 - myapp] Dx 警告:忽略匿名内部类 (iaik.xml.crypto.XSecProvider$2) 的 InnerClasses 属性,该属性没有关联的 EnclosureMethod 属性。此类可能是由未针对现代 .class 文件格式的编译器生成的。推荐的解决方案是从源代码重新编译类,使用最新的编译器并且不指定任何“-target”类型选项。忽略这个警告的后果是对这个类的反射操作会错误地表明它不是一个内部类。

不构建核心库时对核心类(java.* 或 javax.*)的不明智或错误使用。

这通常是由于在使用 IDE(例如 Eclipse)时无意中在应用程序的项目中包含了一个核心库文件。如果您确定自己不是有意定义核心类,那么这就是最有可能的解释。

但是,您实际上可能正在尝试在核心命名空间中定义一个类,例如,您可能从非 Android 虚拟机项目中获取该类的来源。这肯定不会奏效。至少,它会危及您的应用程序与平台未来版本的兼容性。它的合法性也经常受到质疑。

如果您真的打算构建一个核心库——它只适合作为创建完整虚拟机发行版的一部分,而不是编译应用程序——然后使用“--core-library”选项来抑制此错误消息。

如果您继续使用“--core-library”,但实际上正在构建应用程序,那么请预先警告您的应用程序在某些时候仍然无法构建或运行。例如,如果愤怒的客户发现您的应用程序在升级操作系统后停止运行,请做好准备。你会为这个问题负责。

如果您合法地使用某些恰好在核心包中的代码,那么您拥有的最简单安全的替代方法是重新打包该代码。也就是说,将有问题的类移动到您自己的包命名空间中。这意味着它们永远不会与核心系统类发生冲突。JarJar 是一个可以帮助您完成这项工作的工具。如果你发现你不能做到这一点,那么这表明你所走的道路最终会导致痛苦、痛苦、悲伤和悲叹。

[2012-07-18 10:45:48 - myapp] Dx 1 错误;中止

[2012-07-18 10:45:48 - myapp] 转换为 Dalvik 格式失败,错误 1

This is how my project looks int he explorer: http://s14.directupload.net/images/120718/zzy6mmym.jpg

这是我的项目在资源管理器中的外观: http://s14.directupload.net/images/120718/zzy6mmym.jpg

回答by JesusFreke

The problem is that the jar you are including has a class in the java.* or javax.* namespace. dx does not allow this, as mentioned in the last big error message.

问题是您包含的 jar 在 java.* 或 javax.* 命名空间中有一个类。dx 不允许这样做,如上一条大错误消息中所述。

If you actually need these classes, you'll need to move them to a different package, using something like the jarjar tool. Otherwise, you'll need to remove them from the jar -- it may be possible to have proguard to remove them before everything gets dx'd, I'm not sure.

如果您确实需要这些类,则需要使用类似 jarjar 工具的工具将它们移动到不同的包中。否则,您需要将它们从 jar 中取出——在一切都被 dx'd 之前,有可能让 proguard 将它们取出,我不确定。

回答by nomad609

I faced the same problem, I finally resolved it by exporting my private library explicitly.

我遇到了同样的问题,我终于通过明确导出我的私人图书馆解决了这个问题。

Like: Project >> properties >> Java Build Path >> Libraries >> Add External Jars.

比如:项目>>属性>>Java构建路径>>库>>添加外部罐子。

Note: Removed my all private libraries from libs folder. I know it is not correct but it worked for me.

注意:从 libs 文件夹中删除了我的所有私有库。我知道这是不正确的,但它对我有用。

Thanks, Anil

谢谢,阿尼尔

回答by Sandeep_Devhare

Do as follows :

请执行以下操作:

project
  > properties
    > java build path
      > libraries
        > remove all including android jars

Now, go the project browser, right click on the project you are working on, then

现在,转到项目浏览器,右键单击您正在处理的项目,然后

android tools
  > fix project properties.

Do a clean and then build.

做一个清洁,然后构建。

Just restart eclipse, and the error won't occur anymore

重启eclipse,就不会再出现这个错误了

回答by hasanghaforian

If you work on Win7 change this line:

如果您在 Win7 上工作,请更改此行:

call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*     

in proguard.batfile to this:

proguard.bat文件中:

call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9     

proguard.batis in:

proguard.bat在:

[Android SDK Installation Directory]\tools\proguard\bin\proguard.bat

【Android SDK安装目录】\tools\proguard\bin\proguard.bat

Edit:
I hope a combine of these help you:
1-Try to delete libraries projectsfrom your project.
2-Try to export your project(as archive file),delete project and it's source from workspace and then import it again.
3-Try to remove your jars from path,do clean-build and then add them again to your project.

编辑
我希望结合这些可以帮助您:
1-尝试libraries projects从您的项目中删除。
2-尝试导出您的项目(作为存档文件),从工作区中删除项目及其源,然后再次导入。
3-尝试从路径中删除您的罐子,进行清理构建,然后将它们再次添加到您的项目中。

回答by tantigo

I had the same error when using my own obfuscated lib jar.

使用我自己的混淆 lib jar 时,我遇到了同样的错误。

my log:

我的日志:

warning:Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribte.This class was probably prouduced by a compiler that did not target the morden .class file format...

警告:忽略不带有关联 EnclosureMethod 属性的匿名内部类的 InnerClasses 属性。这个类可能是由不针对现代 .class 文件格式的编译器自豪的......

And I solved it like this:before I obfuscate my jar,I added "-keepattributes EnclosingMethod" to the proguard.cfg(or proguard-project.txt in latest android adt version).

我是这样解决的:在混淆我的 jar 之前,我在 proguard.cfg(或最新的 android adt 版本中的 proguard-project.txt)中添加了“-keepattributes EnclosureMethod”。

回答by stuckedoverflow

Agree with hasanghaforian. The easiest solution is to remove libraries project. Right click your project->Properties->Java Build Path then remove Library Projects

同意hasanghaforian。最简单的解决方案是删除库项目。右键单击您的项目-> 属性-> Java 构建路径,然后删除库项目