Since upgrading to 5.0: Unable to convert classes into dex format. See the Console for details.

Ever since upgrading to Unity 5, I haven’t been able to build for android (I only build for android).

Below is the error I get. I use few plugins: google play, OpenIAB, facebook (I hope that’s it, but I had recently removed Amazon - but did so after I got this error, and was hoping removing amazon game circle would help).

CommandInvokationFailure: Unable to convert classes into dex format. See the Console for details.
/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java -Xmx2048M -Dcom.android.sdkmanager.toolsdir="/Users/alex/development/adt-bundle-mac-x86_64-20131030/sdk/tools" -Dfile.encoding=UTF8 -jar "/Applications/Unity/Unity.app/Contents/BuildTargetTools/AndroidPlayer/sdktools.jar" -

stderr[

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/internal/kf$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:732)
	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
	at com.android.dx.command.dexer.Main.access$300(Main.java:82)
	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:279)
	at com.android.dx.command.dexer.Main.run(Main.java:245)
	at com.android.dx.command.dexer.Main.main(Main.java:214)
	at com.android.dx.command.Main.main(Main.java:106)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at SDKMain.main(SDKMain.java:129)
1 error; aborting
]
stdout[
processing archive bin/classes.jar...
processing com/unity3d/player/a$1.class...
processing com/unity3d/player/a$2.class...
processing com/unity3d/player/a$a.class...
processing com/unity3d/player/a.class...
processing com/unity3d/player/b$1.class...
processing com/unity3d/player/b$2.class...
processing com/unity3d/player/b.class...
processing com/unity3d/player/c.class...
processing com/unity3d/player/d$1.class...
processing com/unity3d/player/d$2.class...
processing com/unity3d/player/d.class...
processing com/unity3d/player/e.class...
processing com/unity3d/player/f.class...
processing com/unity3d/player/g.class...
processing com/unity3d/player/h.class...
processing com/unity3d/player/i.class...
processing com/unity3d/player/j$1.class...
processing com/unity3d/player/j$2$1$1.class...
processing com/unity3d/player/j$2$1.class...
processing com/unity3d/player/j$2.class...
processing com/unity3d/player/j.class...
processing com/unity3d/player/k$1.class...
processing com/unity3d/player/k.class...
processing com/unity3d/player/l.class...
processing com/unity3d/player/m.class...
processing com/unity3d/player/n$1.class...
processing com/unity3d/player/n.class...
processing com/unity3d/player/NativeLoader.class...
processing com/unity3d/player/o.class...
processing com/unity3d/player/ReflectionHelper$1.class...
processing com/unity3d/player/ReflectionHelper$a.class...
processing com/unity3d/player/ReflectionHelper.class...
processing com/unity3d/player/p.class...
processing com/unity3d/player/q$1.class...
processing com/unity3d/player/q$2.class...
processing com/unity3d/player/q$3.class...
processing com/unity3d/player/q.class...
processing com/unity3d/player/r.class...
processing com/unity3d/player/s.class...
processing com/unity3d/player/UnityPlayer$1.class...
processing com/unity3d/player/UnityPlayer$2.class...
processing com/unity3d/player/UnityPlayer$3.class...
processing com/unity3d/player/UnityPlayer$4.class...
processing com/unity3d/player/UnityPlayer$5.class...
processing com/unity3d/player/UnityPlayer$6.class...
processing com/unity3d/player/UnityPlayer$7.class...
processing com/unity3d/player/UnityPlayer$8.class...
processing com/unity3d/player/UnityPlayer$9.class...
processing com/unity3d/player/UnityPlayer$10.class...
processing com/unity3d/player/UnityPlayer$11$1.class...
processing com/unity3d/player/UnityPlayer$11.class...
processing com/unity3d/player/UnityPlayer$12.class...
processing com/unity3d/player/UnityPlayer$13.class...
processing com/unity3d/player/UnityPlayer$14.class...
processing com/unity3d/player/UnityPlayer$15.class...
processing com/unity3d/player/UnityPlayer$16.class...
processing com/unity3d/player/UnityPlayer$17.class...
processing com/unity3d/player/UnityPlayer$a.class...
processing com/unity3d/player/UnityPlayer$b.class...
processing com/unity3d/player/UnityPlayer$c.class...
processing com/unity3d/player/UnityPlayer.class...
processing com/unity3d/player/UnityPlayerActivity.class...
processing com/unity3d/player/UnityPlayerNativeActivity.class...
processing com/unity3d/player/UnityPlayerProxyActivity.class...
processing com/unity3d/player/t.class...
processing com/unity3d/player/u$1.class...
processing com/unity3d/player/u.class...
processing com/unity3d/player/WWW.class...
processing org/fmod/FMODAudioDevice$a.class...
processing org/fmod/FMODAudioDevice.class...
processing org/fmod/a.class...
processing bin/classes/./com/facebook/android/R$attr.class...
processing bin/classes/./com/facebook/android/R$color.class...
processing bin/classes/./com/facebook/android/R$dimen.class...
processing bin/classes/./com/facebook/android/R$drawable.class...
processing bin/classes/./com/facebook/android/R$id.class...
processing bin/classes/./com/facebook/android/R$integer.class...
processing bin/classes/./com/facebook/android/R$layout.class...
processing bin/classes/./com/facebook/android/R$raw.class...
processing bin/classes/./com/facebook/android/R$string.class...
processing bin/classes/./com/facebook/android/R$style.class...
processing bin/classes/./com/facebook/android/R$styleable.class...
processing bin/classes/./com/facebook/android/R.class...
processing bin/classes/./com/google/android/gms/R$attr.class...
processing bin/classes/./com/google/android/gms/R$color.class...
processing bin/classes/./com/google/android/gms/R$dimen.class...
processing bin/classes/./com/google/android/gms/R$drawable.class...
processing bin/classes/./com/google/android/gms/R$id.class...
processing bin/classes/./com/google/android/gms/R$integer.class...
processing bin/classes/./com/google/android/gms/R$layout.class...
processing bin/classes/./com/google/android/gms/R$raw.class...
processing bin/classes/./com/google/android/gms/R$string.class...
processing bin/classes/./com/google/android/gms/R$style.class...
processing bin/classes/./com/google/android/gms/R$styleable.class...
processing bin/classes/./com/google/android/gms/R.class...
processing bin/classes/./com/google/example/games/basegameutils/R$attr.class...
processing bin/classes/./com/google/example/games/basegameutils/R$color.class...
processing bin/classes/./com/google/example/games/basegameutils/R$dimen.class...
processing bin/classes/./com/google/example/games/basegameutils/R$drawable.class...
processing bin/classes/./com/google/example/games/basegameutils/R$id.class...
processing bin/classes/./com/google/example/games/basegameutils/R$integer.class...
processing bin/classes/./com/google/example/games/basegameutils/R$layout.class...
processing bin/classes/./com/google/example/games/basegameutils/R$raw.class...
processing bin/classes/./com/google/example/games/basegameutils/R$string.class...
processing bin/classes/./com/google/example/games/basegameutils/R$style.class...
processing bin/classes/./com/google/example/games/basegameutils/R$styleable.class...
processing bin/classes/./com/google/example/games/basegameutils/R.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$attr.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$color.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$dimen.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$drawable.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$id.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$integer.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$layout.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$raw.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$string.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$style.class...
processing bin/classes/./com/google/example/games/mainlibproj/R$styleable.class...
processing bin/classes/./com/google/example/games/mainlibproj/R.class...
processing bin/classes/./com/mildspring/maze/R$attr.class...
processing bin/classes/./com/mildspring/maze/R$color.class...
processing bin/classes/./com/mildspring/maze/R$dimen.class...
processing bin/classes/./com/mildspring/maze/R$drawable.class...
processing bin/classes/./com/mildspring/maze/R$id.class...
processing bin/classes/./com/mildspring/maze/R$integer.class...
processing bin/classes/./com/mildspring/maze/R$layout.class...
processing bin/classes/./com/mildspring/maze/R$raw.class...
processing bin/classes/./com/mildspring/maze/R$string.class...
processing bin/classes/./com/mildspring/maze/R$style.class...
processing bin/classes/./com/mildspring/maze/R$styleable.class...
processing bin/classes/./com/mildspring/maze/R.class...
processing archive plugins/./android-support-v4.jar...
ignored resource META-INF/MANIFEST.MF
processing android/support/annotation/ArrayRes.class...
processing android/support/annotation/StyleableRes.class...
processing android/support/annotation/RawRes.class...
processing android/support/annotation/InterpolatorRes.class...
processing android/support/annotation/PluralsRes.class...
processing android/support/annotation/DrawableRes.class...
processing android/support/annotation/ColorRes.class...
processing android/support/annotation/IntDef.class...
processing android/support/annotation/BoolRes.class...
processing android/support/annotation/XmlRes.class...
processing android/support/annotation/LayoutRes.class...
processing android/support/annotation/IdRes.class...
processing android/support/annotation/AttrRes.class...
processing android/support/annotation/AnimatorRes.class...
processing android/support/annotation/StringRes.class...
processing android/support/annotation/NonNull.class...
processing android/support/annotation/DimenRes.class...
processing android/support/annotation/Nullable.class...
processing android/support/annotation/MenuRes.class...
processing android/support/annotation/StringDef.class...
processing android/support/annotation/AnyRes.class...
processing android/support/annotation/FractionRes.class...
processing android/support/annotation/StyleRes.class...
processing android/support/annotation/IntegerRes.class...
processing android/support/annotation/AnimRes.class...
processing android/support/v4/app/RemoteInput$ImplApi20.class...
processing android/support/v4/app/Fragment$InstantiationException.class...
processing android/support/v4/app/RemoteInput.class...
processing android/support/v4/app/Fragment.class...
processing android/support/v4/app/FragmentTransitionCompat21$2.class...
processing android/support/v4/app/LoaderManager$LoaderCallbacks.class...
processing android/support/v4/app/FragmentManager$OnBackStackChangedListener.class...
processing android/support/v4/app/NotificationCompatApi20$Builder.class...
processing android/support/v4/app/FragmentTransitionCompat21$ViewRetriever.class...
processing android/support/v4/app/NotificationCompatIceCreamSandwich.class...
processing android/support/v4/app/TaskStackBuilderHoneycomb.class...
processing android/support/v4/app/NoSaveStateFrameLayout.class...
processing android/support/v4/app/NotificationCompat$CarExtender$UnreadConversation$1.class...
processing android/support/v4/app/RemoteInput$ImplJellybean.class...
processing android/support/v4/app/NavUtils$NavUtilsImplBase.class...
processing android/support/v4/app/NotificationCompat.class...
processing android/support/v4/app/RemoteInputCompatJellybean.class...
processing android/support/v4/app/FragmentManagerState.class...
processing android/support/v4/app/BackStackState.class...
processing android/support/v4/app/NotificationCompatApi21.class...
processing android/support/v4/app/NotificationCompat$WearableExtender.class...
processing android/support/v4/app/ListFragment$2.class...
processing android/support/v4/app/ShareCompatICS.class...
processing android/support/v4/app/LoaderManager.class...
processing android/support/v4/app/FragmentTransaction.class...
processing android/support/v4/app/NotificationCompat$NotificationCompatImplJellybean.class...
processing android/support/v4/app/RemoteInput$ImplBase.class...
processing android/support/v4/app/ActionBarDrawerToggle$SlideDrawable.class...
processing android/support/v4/app/NotificationManagerCompat$NotifyTask.class...
processing android/support/v4/app/BackStackRecord$1.class...
processing android/support/v4/app/NotificationManagerCompat$SideChannelManager.class...
processing android/support/v4/app/ActivityOptionsCompat21.class...
processing android/support/v4/app/RemoteInput$1.class...
processing android/support/v4/app/ActionBarDrawerToggleHoneycomb$SetIndicatorInfo.class...
processing android/support/v4/app/INotificationSideChannel$Stub.class...
processing android/support/v4/app/NotificationCompatApi21$Builder.class...
processing android/support/v4/app/TaskStackBuilder$TaskStackBuilderImpl.class...
processing android/support/v4/app/TaskStackBuilder$TaskStackBuilderImplBase.class...
processing android/support/v4/app/NavUtils.class...
processing android/support/v4/app/NotificationManagerCompatIceCreamSandwich.class...
processing android/support/v4/app/TaskStackBuilder$TaskStackBuilderImplJellybean.class...
processing android/support/v4/app/NotificationManagerCompat.class...
processing android/support/v4/app/ShareCompat$IntentBuilder.class...
processing android/support/v4/app/NotificationCompatBase$Action.class...
processing android/support/v4/app/RemoteInputCompatApi20.class...
processing android/support/v4/app/FragmentTransaction$Transit.class...
processing android/support/v4/app/BackStackRecord$2.class...
processing android/support/v4/app/NotificationCompatKitKat$Builder.class...
processing android/support/v4/app/NotificationManagerCompatEclair.class...
processing android/support/v4/app/SharedElementCallback.class...
processing android/support/v4/app/NotificationCompatJellybean$Builder.class...
processing android/support/v4/app/BundleUtil.class...
processing android/support/v4/app/FragmentContainer.class...
processing android/support/v4/app/NotificationBuilderWithActions.class...
processing android/support/v4/app/FragmentManagerImpl$2.class...
processing android/support/v4/app/NotificationCompatSideChannelService.class...
processing android/support/v4/app/NotificationManagerCompat$SideChannelManager$ListenerRecord.class...
processing android/support/v4/app/FragmentState.class...
processing android/support/v4/app/ActionBarDrawerToggle$ActionBarDrawerToggleImpl.class...
processing android/support/v4/app/NotificationCompatApi20.class...
processing android/support/v4/app/NavUtils$NavUtilsImpl.class...
processing android/support/v4/app/NotificationCompat$Builder.class...
processing android/support/v4/app/DialogFragment$DialogStyle.class...
processing android/support/v4/app/Fragment$SavedState$1.class...
processing android/support/v4/app/ActivityOptionsCompat$ActivityOptionsImplJB.class...
processing android/support/v4/app/ActivityOptionsCompat$ActivityOptionsImpl21.class...
processing android/support/v4/app/ActionBarDrawerToggle.class...
processing android/support/v4/app/NotificationCompat$NotificationCompatImplHoneycomb.class...
processing android/support/v4/app/NotificationManagerCompat$Impl.class...
processing android/support/v4/app/NotificationCompat$Action$Extender.class...
processing android/support/v4/app/ShareCompatJB.class...
processing android/support/v4/app/NavU

Found the problem - google play services library existed twice, not sure how it happened. Here’s a command I ran, in case someone else will need it:

Aleksandrs-MBP:maze alex$ find . -name "*.jar" | sed -e "s:\(.*\)/\([^/]*\)$:\2 \1:" | sort

OpenIAB-plugin.jar ./Maze/Assets/Plugins/Android

android-support-v4.jar ./Maze/Assets/Facebook/Editor/android/android-libs

android-support-v4.jar ./Maze/Assets/Plugins/Android

base-game-utils.jar ./Maze/Assets/Plugins/Android/BaseGameUtils/libs

classes.jar ./Maze/Assets/Plugins/Android/facebook/bin

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

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

play-games-plugin-support.jar ./Maze/Assets/Plugins/Android/MainLibProj/libs

unity-classes.jar ./Maze/Assets/Facebook/Editor/android/android-libs

unity-plugin-library.jar ./Maze/Assets/Plugins/Android

Aleksandrs-MBP:maze alex$ pwd

/Users/alex/documents/development/unity/maze

I have removed the duplicate by running

rm -rf ./Maze/Assets/Plugins/google-play-services_lib