简体   繁体   English

Proguard错误:多个dex文件定义了活动

[英]Proguard error: Multiple dex files define Activity

I've heard that lots of people get this error: 我听说很多人收到此错误:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lfoo.bar.MyActivity;

However none of the solutions I found on StackOverflow works for me. 但是,我在StackOverflow上找到的所有解决方案都不适合我。

I read that this error may be caused when you include multiple times in the project the same library, but the strange thing is that foo.bar.MyActivity is defined in only one library, and that library is included only once in my project. 我读到,当您在项目中多次包含同一个库时,可能会导致此错误,但奇怪的是foo.bar.MyActivity仅在一个库中定义,并且该库在我的项目中仅包含一次。

Please note that foo.bar.MyActivity is defined in an Android library, not in a jar. 请注意foo.bar.MyActivity是在Android库中定义的,而不是在jar中定义的。

Another strange thing is that I can compile and run the app correctly if I turn ProGuard off: the error shows up only after the pre-dexing done by Proguard (so the second one in the compilation process). 另一个奇怪的事情是,如果我关闭ProGuard,我可以正确地编译和运行该应用程序:仅在Proguard进行了预排序之后,该错误才会显示(因此是编译过程中的第二个错误)。

Here's the complete stack trace of the error that proguard gives: 这是proguard给出的错误的完整堆栈跟踪:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lfoo.bar.MyActivity;
Merged dex A (4111 defs/3053.8KiB) with dex B (47 defs/47.0KiB). Result is 4158 defs/3628.2KiB. Took 0.6s
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
    at com.android.dx.command.dexer.Main.run(Main.java:230)
    at com.android.dx.command.dexer.Main.main(Main.java:199)
    at com.android.dx.command.Main.main(Main.java:103)

Do you have any idea on how to solve my issue? 您是否有解决我问题的想法?

PS: I use Ant to compile the app. PS:我使用Ant来编译应用程序。

Thanks a lot for your time. 非常感谢您的宝贵时间。

Additional Infos: I use Netbeans with nbandroid to build the app 其他信息:我将Netbeans与nbandroid一起使用来构建应用程序

try this hope it may solve your problem 尝试这个希望可以解决您的问题

I had the same problem, quite weird because it was happening only when using Eclipse (but it was OK with Ant). 我有同样的问题,很奇怪,因为它仅在使用Eclipse时才发生(但使用Ant可以)。 This is how I fixed it: 这是我解决的方法:

Right click on the Project Name Select Build Path -> Configure Build Path In Java Build Path, go to the tab Order and Export 右键单击项目名称,选择Build Path-> Configure Build Path在Java Build Path中,转到选项卡Order and Export

Uncheck your .jar library 取消选中.jar库

Only sometimes: In Order and Export tab I did not have any jar library there, so I have unchecked Android Private Libraries item. 仅在某些情况下:在“订单和导出”选项卡中,我那里没有任何jar库,因此我没有选中“ Android Private Libraries”项。 Now my project is running. 现在我的项目正在运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM