Honkbark studios menu logo

Troubleshooting Unable to convert classes into dex format in unity

Troubleshooting Unable to convert classes into dex format in unity

Please share this post with your friends

This technique was used while developing Friendsheep.

When building an android package of your unity game you might come across this error message. And specially if you use a few different assets from the asset store.

Error building Player: CommandInvokationFailure: Unable to convert classes into dex format. See the Console for details.

And the console might say the following:

/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java -Xmx2048M -Dcom.android.sdkmanager.toolsdir=”/Users/<path>/android-sdk-macosx/tools” -Dfile.encoding=UTF8 -jar “/Applications/Unity/Unity.app/Contents/PlaybackEngines/AndroidPlayer/Tools/sdktools.jar” –

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/google/gson/Gson$5;
	at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
	at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
	at com.android.dx.command.dexer.Main.processClass(Main.java:732)
	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
	at com.android.dx.command.dexer.Main.access$300(Main.java:83)
	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
	at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
	at com.android.dx.command.dexer.Main.processOne(Main.java:632)
	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
	at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
	at com.android.dx.command.dexer.Main.run(Main.java:246)
	at com.android.dx.command.dexer.Main.main(Main.java:215)
	at com.android.dx.command.Main.main(Main.java:106)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at SDKMain.main(SDKMain.java:129)
1 error; aborting

Our problem here is this line:

java.lang.IllegalArgumentException: already added: Lcom/gooogle/gson/Gson$5

And to solve the problem we look at the class after the last “:” which is Lcom/google/gson/Gson
This indicates that we have more than one class called Gson. This might be because more than one of your unity assets imported their own version of this file. The solution is to make sure only one of these exist. I found it simple to search for this class in finder(or explorer for windows users). When you found the duplicates, select one, check in what unity folder it exist, open unity again and browse to that path and simply delete it. Now you should be able to build the project.

Categories: Unity3D