How to: Solve the “Unable to convert classes into dex format” Unity error

I recently came across the following error when trying to build my game in Unity “Unable to convert classes into dex format. See the Console for details.”

Unity error dialog stating: Unable to convert classes into dex format. See the Console for details.

The console error is pretty long but starts with:

Error building Player: CommandInvokationFailure: Unable to convert classes into dex format. See the Console for details.
C:\Program Files\Java\jdk1.6.0_38\bin\java.exe -Xmx1024M -Dcom.android.sdkmanager.toolsdir="E:/adt-bundle-windows-x86-20131030/sdk\tools" -Dfile.encoding=UTF8 -jar "E:/unity/Editor/Data/BuildTargetTools/AndroidPlayer\sdktools.jar" -

stderr[

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/common/internal/safeparcel/a;
	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:685)
	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
	at com.android.dx.command.dexer.Main.access$600(Main.java:78)
	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
	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:596)
	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
	at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
	at com.android.dx.command.dexer.Main.run(Main.java:230)
	at com.android.dx.command.dexer.Main.main(Main.java:199)
	at com.android.dx.command.Main.main(Main.java:103)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at SDKMain.main(SDKMain.java:129)
1 error; aborting
]
...

After a bit of digging I found this: Multiple plugin conflict

The answer does a really good job of explaining the issue, essentially you have two classes named the same. In most cases this is because you’ve more than one copy of the same JAR file in your build. I did a quick search of ‘*.jar’ and looked for duplicates. In my case I had:

Assets/Plugins/Android/google-play-services.jar
Assets/Plugins/Android/google-play-services_lib/libs/google-play-services.jar

Having deleted one copy I could then re-run the build successfully.