Dex Error when I include .jar files into my android project

孤街浪徒 提交于 2019-12-11 05:48:10

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/47514818/dex-error-when-i-include-jar-files-into-my-android-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!