1

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

Jack
  • 491
  • 7
  • 27
  • 1
    I suggest that you edit your question and provide the complete output of the Gradle Console, not just that one error line. Usually, the source of your problems (e.g., duplicate classes) appears elsewhere in the Gradle Console output. In general, try not to use JARs, but instead use artifacts in repositories. – CommonsWare Nov 27 '17 at 15:52
  • It is probably because on incompatibitliy. Try enabling multidex by adding `multiDexEnabled true' inside `defaultConfig{ }` in your gradle. – Jimmy Nov 27 '17 at 15:53
  • I tried adding the multidexenable but that doesnt help, also there is really nothing else in the gradle console but ill add the rest anyways – Jack Nov 27 '17 at 16:03

1 Answers1

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.

Shubham Shekhar
  • 316
  • 3
  • 17