使用ant或Eclipse编译时出现多个dex文件错误
我无法构建我的应用程序 我正在运行今天下载的最新构建工具,这种情况在更新后开始发生。
-dex:
[dex] Converting compiled files and external libraries into
/Users/rob/Repos/my_app/bin/classes.dex...
[dx]
[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] com.android.dx.util.DexException: Multiple dex files define
Lcom/robaldred/myapp/About$1;
我尝试过清理和重建,我也在 Eclipse 中尝试过,但它给出了相同的错误。 有人有什么想法吗?我现在就在这里的一堵砖墙上。
I am unable to build my application
I am running the latest build tools downloaded today, this started happening after the update.
-dex:
[dex] Converting compiled files and external libraries into
/Users/rob/Repos/my_app/bin/classes.dex...
[dx]
[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] com.android.dx.util.DexException: Multiple dex files define
Lcom/robaldred/myapp/About$1;
I have tried cleaning and rebuilding, I've also tried in Eclipse but it gives the same error.
Anyone got any ideas? I'm at a brick wall here now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我花了几个小时清理、创建新项目、卸载重新安装 sdk...没有任何效果。我也没有任何库项目(我只是在 lib 下有一些 jar 文件)。然而,最后我修复了它,我的步骤是:
I spent hours cleaning, creating new projects, uninstalling-reinstalling sdk... nothing worked. I didnt have any library project either ( i just had some jar files under lib). Howerver, In the end I fixed it and my steps were:
昨天我的系统(以及工作中的另一个系统)发生了一些事情,其中 SDK 想要推送平台工具更新,但后来我根本无法使用它,等等。
我最终将我的 SDK 移开并重新安装它,然后一切都像往常一样进行。我没有遇到你的 dex 特定问题,但我怀疑昨天的更新推送破坏了很多东西。祝你好运。
Something happened yesterday to my system (and another here at work) where the SDK wanted to push the platform tools update but then I was unable to use it at all, etc.
I ended up moving my SDK out of the way and reinstalling it, then everything worked as it always had. I did not have your dex specific issue, but I suspect the update push yesterday broke a good many things. Good luck.
您可以:
删除文件夹
<.settings>
、
、
和文件<.classpath>
、<.project>
和
。在 Eclipse 中删除您的项目(右键,
),而不删除源文件。创建一个新的 Android 项目,然后从之前的源中选择
。导入外部库(如果构建路径中需要)。
它应该可以解决这个恼人的问题。
You can:
Delete folders
<.settings>
,<bin>
,<gen>
, and files<.classpath>
,<.project>
and<project.properties>
.Delete your project in Eclipse (right button,
<Delete>
) without deleting the source files.Create a new Android project and select
<Create project from existing sources>
from your previous sources.Import external libs, if needed in the build path.
It should solve this annoying problem.
请务必小心项目中附加的/拥有的所有源文件。
我在两种情况下发现了这个问题:
src
放入过去时,不是作为库,而是直接放入我的 src 目录所以所有答案都说您不应该将 bin/ 目录放入类路径中也是正确的,但是在出现以下错误的情况下:
您应该在项目/库中查找相同的 jar(在大多数情况下,这应该由 Android Eclipse 环境创建)或查看项目附加的所有来源以查找com.facebook.android.AsyncFacebookRunner 类多次出现(如上面的示例代码所示)
Be very careful about all source files you attach to/have in your project.
I found this problem in two situations:
src
not as a library, but directly into my src directorySo all answers which says that you shouldn't put your bin/ directory into class path are also correct, but in situation where you have error like:
you should look for same jars in project/libraries (this should be founded by Android Eclipse environment in most cases) or look into all sources attached to project to find multiple occurance of (as in example code above) of class
com.facebook.android.AsyncFacebookRunner
我认为 bin 中的目录从 变为
您
可以清理您的项目并解决它。
I think the directory in bin change from
to
You can clean your project and solve it.
我也看到了同样的问题。如果您使用的是 Android Studio,则需要确保在编译时任何项目中都没有包含“bin”或“gen”文件夹。
删除后我能够成功编译
I was seeing this same problem. If you're using Android Studio, you need to make sure you don't have the 'bin' or 'gen' folders included in any of your projects when you're compiling.
After removing this I was able to compile successfully
如果您因多个 DEX 文件而遇到问题,
请删除整个目标文件夹并再次构建项目。这不会影响您的项目,因为目标文件夹中的所有内容都会重新构建。
If you're having issues because of Multiple DEX files
Remove the entire target folder and build the project again. This won't affect your project cause everything in the target folder is built again.
将实现 fileTree(include: ['.jar'], dir: 'libs') 更改为
在您的应用程序 gradle.build> 中提供了 fileTree(include: ['.jar'], dir: 'libs')依赖关系。
确保您的“模块设置”中已更改>依赖项 {include=[*jar] dir=libs} 也是如此。它旁边必须有一个“提供”范围,而不是“实现”。
Change implementation fileTree(include: ['.jar'], dir: 'libs') to
provided fileTree(include: ['.jar'], dir: 'libs') in your app gradle.build> dependencies.
Make sure it has changed in your Module Settings> Dependencies {include=[*jar] dir=libs} too. It must have a scope of Provided next to it and not Implementation.