Error Building Player: Commandinvokationfailure: Unable to Convert Classes into Dex Format

Unable to convert classes into dex format Unity

Some Background

When Unity builds your project for Android, it invokes several tools from the Android SDK. As part of that process, it converts all of your native (Java) code for Android into a file format called DEX (Dalvik executable).

All of your Android plugins get built up into a single package using that tool. The problems start when a few plugins have the same compiled Java code (classes) in them. This will cause the DEX tool to fail with an error like the one you're seeing:

Uncaught translation error: java.lang.IllegalArgumentException:
already added: Lcom/google/android/gms/internal/zzbyb;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/internal/zzbyc;

This means that classes with those names were already included in another library, and so they cannot be added again.

Possible Causes

As explained above, this error occurs when you have duplicate plugins in your project; this can happen in different scenarios, here are some examples:

  • The same plugin is included more than once, under different folders of the project.
  • The same plugin is included more than once with different versions.
  • A plugin contains other dependencies "embedded" inside it, but these dependencies are already included in the project in some form.

How To Fix

You should look up duplicate Android plugins in your project and eliminate them (keep only 1 copy). From the error message you posted, the issue here is related to Google play services libraries. You should look into that (libraries named play-services-xxxx.aar).

Paid Help (Shameless Plug)

I provide a professional service for fixing this exact kind of issue. In case you (or anyone else) are not able to resolve such an issue themselves, feel free to contact me and get it solved.

Unity Error: Unable to convert classes into dex format

The classes.jar (which you later renamed it to 'unity_classes.jar') gets automatically included into the built .apk by Unity, so you shouldn't include it yourself again (in your Android plugin), even under a different name.

In other words, first your android plugin "embeds" this .jar file inside itself. Then, when Unity adds your plugin into the game project, it also adds its own copy of that .jar file (it does that for all android projects). Consequently, Unity essentially ends up having 2 copies of the same .jar file in the project and complains by saying 'unable to convert classes into dex format'.

So although you have to use this library (.jar file) in your project but you should not bundle this library with your project. How to do that? If you're using Android studio, you can achieve this by marking the .jar file as a dependency with the provided scope.

To do this, you can:

1) Go to 'build.gradle' of your module and change this:

compile files('libs/jars/unity_classes.jar')

to this:

provided files('libs/jars/unity_classes.jar')

Or

2) you can right-click on the module (in Android pane) and choose Open Module Settings. Then go to Dependencies tab. Find the Unity module (which I renamed it to unity_classes.jar) and change its scope to Provided.

Unity - Unable to convert classes into dex format. (Unity Ads & Unity IAP)

Unsupported major.minor version 52.0

This is telling you that the classes were compiled with the JDK for Java 8. (Source) However, your JDK is for Java 7 (C:\Program Files\Java\jdk1.7.0_79\bin\java.exe). Download and install a newer JDK and try again.



Related Topics



Leave a reply



Submit