“转换为 Dalvik 格式失败,错误 1”更新到 ADT 14 后

发布于 12-11 08:59 字数 236 浏览 3 评论 0原文

更新到最新的开发人员工具 ADT 14 后,包含库项目的 Android 项目将不再运行并产生错误:

Dx UNEXPECTED TOP-LEVEL EXCEPTION: ... already added: ...
...
Conversion to Dalvik format failed with error 1

描述此问题的其他线程及其解决方案(包括删除和重新添加项目)不起作用。

After updating to the latest developer tools, ADT 14, my Android project that includes library projects will no longer run producing the error:

Dx UNEXPECTED TOP-LEVEL EXCEPTION: ... already added: ...
...
Conversion to Dalvik format failed with error 1

The other threads describing this issue with solutions that include removing and re-adding the projects do not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

静待花开2024-12-18 08:59:19

此问题被列为 ADT 14 的已知问题。以下是 Android Tools 项目网站的引用:

项目未构建时出现错误
[2011-10-20 23:32:04 - MyApp] Dx 意外顶级异常::已添加:
这是由于未能从库中删除以前的库源文件夹
主要项目。顺便说一句,这些链接源的脆弱性
文件夹是我们放弃这种机制的原因之一
(更多信息请参见
http://tools.android.com/recent/buildchangesinrevision14)。这
解决方案是从中删除那些 _src 源文件夹
你的项目。只需右键单击它们并选择 Build Path >消除
来自构建路径
。系统还会提示您删除链接的
你应该做的文件夹。如果没有提示,请将其删除
手动。您可以在这个伟大的文章中看到问题的一些屏幕截图
邮政:
http ://android.foxykeep.com/dev/fix-the-conversion-to-dalvik-format-failed-with-error-1-with-adt-14

解决方案:

作为它说,解决方案是从项目中删除 _src 源文件夹。您可以通过右键单击它们并选择“构建路径 -> 从构建路径中删除”或在项目属性中(Java 构建路径 -> 源选项卡)来完成此操作。

This problem is listed as a known issue of ADT 14. Here's the quote from the Android Tools Project Site:

Project not building with error
[2011-10-20 23:32:04 - MyApp] Dx UNEXPECTED TOP-LEVEL EXCEPTION:<class>: already added: <class>
This is due to a failure to remove previous library source folders from the
main project. Incidentally, the fragility around those linked source
folders is one of the reason we are moving away from this mechanism
(see more info at
http://tools.android.com/recent/buildchangesinrevision14). The
solution is to remove those <libraryname>_src source folders from
your projects. Just right click them and choose Build Path > Remove
from Build Path
. You should also be prompted to remove the linked
folder which you should do. If you're not prompted, remove it
manually. You can see some screenshot of the problem in this great
post:
http://android.foxykeep.com/dev/fix-the-conversion-to-dalvik-format-failed-with-error-1-with-adt-14

Solution:

As it says, the solution is to remove the <libraryname>_src source folders from your projects. You can do this by right clicking them and choose "Build Path -> Remove from Build Path" or in your project properties (Java Build Path -> Source tab).

ぇ气2024-12-18 08:59:19

我也遇到了这个问题,但以上方法都没有解决它:

  • 尝试删除/重新添加带有干净构建的库,
  • 尝试删除并重新导入项目

没有骰子。每次我尝试导出到 apk 时,“转换为 Dalvik 格式失败,错误 1”仍然在我面前出现。

我可以看出问题与 ProGuard 有关,因为当我在 project.properties 文件中注释掉这一行时,一切正常:

proguard.config=proguard.cfg

但是,直到我发现 < a href="http://davematthew.blogspot.com/2011/10/compiling-with-android-adt-14.html" rel="noreferrer">David M Young 的这篇文章。显然,ADK/ADT 14 附带了错误版本的 ProGuard(糟糕!)。我下载了 ProGuard 版本 4.6。将 android-sdk\android-sdk\tools\proguard\lib 目录内容替换为 proguard4.6.zip\proguard4.6\lib(3 个 *.jar 文件) ,重新启动 Eclipse 并导出到 apk 再次工作!

I also ran into this problem, but none of the above fixed it:

  • Tried removing/re-adding libraries with clean builds along the way
  • Tried deleting and re-importing projects

No dice. Still the "Conversion to Dalvik format failed with error 1" was staring me in the face every time I tried to export to an apk.

I could tell the problem was related to ProGuard, because when I commented out this line in my project.properties file, everything worked fine:

proguard.config=proguard.cfg

However, I wasn't able to solve the problem until I found this post by David M Young. Apparently, ADK/ADT 14 shipped with an incorrect version of ProGuard (oops!). I downloaded ProGuard version 4.6. Replaced the android-sdk\android-sdk\tools\proguard\lib directory contents with proguard4.6.zip\proguard4.6\lib (3 *.jar files), restarted Eclipse and export to apk worked again!

计㈡愣2024-12-18 08:59:19

要解决这个问题,您应该:

  • 右键单击您的项目>属性>Java构建路径并删除除一个Android IJ(取决于您的版本)之外的所有库
  • 项目>清理
  • 添加回您已删除的库

如果问题再次出现,那么它是将库放在项目之外并将它们作为“外部 JAR”导入非常有用

To solve you should:

  • Right click on your project>Properties>Java Build Path and remove all libs but the one Android I.J (depending on your version)
  • Project>Clean
  • Add back the libs you've removed

If the problem comes back another times it's useful to put the libs outside your project and import them as "External JARs"

浅笑依然2024-12-18 08:59:19

你好,我想我会在这里投入两分钱。正如我所做的那样,

“_src -> 从路径中删除”

然后我清理并重建它,我可以让它在我的手机上以调试模式运行就好了。我也可以导出它;但前提是我禁用了 proguard。当然,我不能就这样让我的代码开放给所有人看。所以这很让人抓狂。但我终于找到了一种治疗方法,奇怪的是,他们在 r12 上遇到了与此相同的问题(并修复了)。

它位于:[Android SDK安装目录]\tools\proguard\bin\proguard.bat

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

更改为

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

我尝试了很多其他东西,但这就是所做的对我来说。

Hello thought I'd throw my two cents in here. as I did do that,

"_src -> Remove from path"

Then I cleaned it and rebuilt and I could get it to run in debug mode on my phone just fine. I could also export it; but only if I disabled proguard. of course I couldn't leave it like that with my code open for all to see. so it was quite madding. but I Finally found a cure, oddly enough they had the same problem (and fix) with r12 as they do with this one.

it's in: [Android SDK Installation Directory]\tools\proguard\bin\proguard.bat

Change

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

to

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

I tried tons of other stuff but this is what did it for me.

听风吹2024-12-18 08:59:19

这是 android sdk 的一个已知问题。看看这个 博客文章 进行修复。

This is a known problem with the android sdk. Check out this blogpost for a fix.

凉风有信2024-12-18 08:59:19

我在我的项目中使用了一个库,并且遇到了同样的错误 - 通过删除库和 src 文件夹、清理并将其添加回来并再次清理来解决。

删除

  1. 项目属性 -> Android:删除库,“应用”
  2. 删除包含的库 src-folder
  3. 更好地清理,

再次添加

  1. 项目属性 -> Android:再次添加库,“应用”
  2. 清理项目

I used a library for my project and had the same error - it was solved by removing library and src-folder, cleaning and adding it back and cleaned again.

Remove

  1. Project properties -> Android: Remove libs, 'Apply'
  2. Remove included library src-folder
  3. better clean,

Add again

  1. Project properties -> Android: Add libs again, 'Apply'
  2. Clean project
日暮斜阳2024-12-18 08:59:19

只是这个问题再次出现(通过删除其他答案中提到的 _src 项目第一次修复) - 这次没有 _src 文件要删除。该错误与 android-support-v4.jar 相关,它作为链接库项目的一部分以及主项目本身的一部分包含在内。

错误 Dx 意外的顶级异常:
java.lang.IllegalArgumentException:已添加:Landroid/support/v4/content/ModernAsyncTask$WorkerRunnable;

从主项目的构建路径中删除 android-support-v4.jar 文件后,问题就消失了。我不认为这是导致错误的可能原因。

Just had this problem come back again (fixed first time by removing the _src items as mentioned in other answers) - this time there were no _src files to remove. The error was relating the android-support-v4.jar which was included as part of a linked library project as well as part of the main project itself.

Error Dx UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/content/ModernAsyncTask$WorkerRunnable;

Problem went away after removing the android-support-v4.jar file from the build path for the main project. Don't think I came across this as possible cause to the errors.

枕头说它不想醒2024-12-18 08:59:19

转到项目 » 属性 » Java 构建路径 » 库并删除除“Android XY”(在我的例子中为 Android 1.5)之外的所有内容。单击“确定”。转到项目 » 清理 » 清理下面选择的项目 » 选择您的项目,然后单击确定。那应该有效。

您的项目文件夹中也可能有一个 JAR 文件(我已将 Admob JAR 文件复制到我的 src 文件夹中),然后将其添加为 Java 路径库。它不会显示在 Package Explorer 下,因此您不会注意到它,但它确实会被计数两次,从而导致可怕的 Dalvik 错误 1。

另一个可能的原因可能是包名称冲突。假设您有一个包 com.abc.xyz 和该包内一个名为 A.java 的类,以及另一个包含相同 com.abc.xyz.A.java 的库项目(已添加到该项目的依赖项中),那么你会得到完全相同的错误。这意味着,您对同一文件 A.java 有多个引用,并且无法正确构建它。

Go to Project » Properties » Java Build Path » Libraries and remove all except the "Android X.Y" (in my case Android 1.5). click OK. Go to Project » Clean » Clean projects selected below » select your project and click OK. That should work.

It is also possible that you have a JAR file located somewhere in your project folders (I had copied the Admob JAR file into my src folder) and THEN added it as a Java Path Library. It does not show up under the Package Explorer, so you don't notice it, but it does get counted twice, causing the dreaded Dalvik error 1.

Another possible reason could be package name conflicts. Suppose you have a package com.abc.xyz and a class named A.java inside this package, and another library project (which is added to the dependency of this project) which contains the same com.abc.xyz.A.java, then you will be getting the exact same error. This means, you have multiple references to the same file A.java and can't properly build it.

不醒的梦2024-12-18 08:59:19

我遇到了同样的问题,我正在使用 ADT 20.0.3。

我遵循的步骤来解决这个问题。

删除project/lib文件夹中的所有jar并将它们引用为外部jar。
检查项目中的 android 依赖项/参考库是否有重复项,

I had the same issue, I'm using the ADT 20.0.3.

Steps I followed to resolve this.

Remove all the jar in project/lib folder and reference them as external jars.
Check android dependencies/reference libraries in project for duplicates,

行雁书2024-12-18 08:59:19

我在项目中使用 Sherlock ActionBar 库时解决了这个问题。您可以执行以下步骤,这对我有用。

右键单击您的项目,选择属性。
将显示一个对话框,在左侧菜单中选择“Java 构建路径”。
删除右侧面板上的“Android依赖项”和“Android私有库”,然后单击“确定”
清理您的项目(选择菜单“Project --> Clean”)
右键单击您的项目,选择 Android Tools ->修复项目属性
再次清理项目。
重新启动计算机
打开eclipse并导出apk
希望这会对您有所帮助。

I've dealt with this problem when using Sherlock ActionBar library in my project. You could do the following step, it's work for me.

Right click to your project, select properties.
A dialog will show up, select 'Java build path' on the left menu.
Remove 'Android dependencies' and 'Android private libraries' on the right panel then click OK
Clean your project (select menu Project --> Clean)
Right click your project, select Android Tools -> Fix project properties
Clean project once again.
Restart your computer
Open eclipse and Export apk
Hope that will help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文