当我将.jar文件包含到我的android项目中时出现Dex错误 [英] Dex Error when I include .jar files into my android project

查看:132
本文介绍了当我将.jar文件包含到我的android项目中时出现Dex错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将2个.jar文件包含到我的android项目中,方法是将它们拖到我的libs文件夹中,然后再通过 Build-> Edit Library and Dependencies-> jar Dependency 添加它们>,无论是否有最后一步,我都完成了此操作,不过,如果尝试运行应用程序时将它们添加到我的libs文件夹中,我都会得到:

Information:Gradle任务[:app:assembleDebug] 错误:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败.

java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex 信息:10秒内失败 信息:1个错误 信息:0警告 信息:在控制台中查看完整的输出

但是,如果我从libs文件夹中删除文件,错误消失了,问题是我显然想在我的应用程序中使用这些jar文件.通过添加和删除jar文件

谢谢

解决方案

如果您阅读.但是,在您的情况下,我建议您转到应用程序级别的gradle文件,并删除所有不必要的依赖项和冗余依赖项(如果存在).另外,请尝试仅导入项目实际需要的依赖项,例如,如果您需要从Google Play服务中获取库,则不要导入整个Google Play服务库,而仅导入项目中实际需要的依赖项.

如果可能,还尝试查找可以替换当前jar文件的jar文件.

PS:您能让我知道您要导入的jar文件的名称吗?这可能有助于轻松解决问题.

Im trying to include 2 .jar files into my android project I do this by dragging them into my libs folder and then after I also add them via Build->Edit Library and Dependencies->jar Dependency, I have done it with or without this last step, either way though when I add them to my libs folder if I try to run the app I get:

Information:Gradle tasks [:app:assembleDebug] Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex Information:BUILD FAILED in 10s Information:1 error Information:0 warnings Information:See complete output in console

But if I delete the files from my libs folder the error goes away, the problem is I obviously want to use these jar files for my app Ive seen other dex error topics here but none seem to address the issue when it happens like this via adding and removing jar files

Thanks

解决方案

If you read this document, you will get to know that Android app (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536 or 64k methods. The jar files you are using contains Classes and methods. Adding them to your projects must be surpassing the maximum allowed 64k methods mark and thus it generates the error.

This problem is a common one and has a lot of solutions available, for eg this. However, in your case I would recommend you to do go to your app level gradle file and remove all unnecessary dependencies and redundant dependencies(if present). Also try to import only those dependencies which are actually needed by the project, for eg, if you require libraries from Google play services, instead of importing the entire google play services library, import only those which are actually needed by your project.

Also if possible, try to find jar files which which can replace your current jar files.

PS: Can you let me know the names of the jar files you are trying to import. It may help in resolving the issue in an easy way.

这篇关于当我将.jar文件包含到我的android项目中时出现Dex错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆