Unity 2018.3 android dex merging issue

Viewed 4327

Before you decide to dismiss this post as "duplicate" without even reading it, understand that I have looked at a TON of posts related to this topic and I can't find a solution for my instance, including all of the ones that StackOverflow suggested. Most of the posts are for Android Studio instead of unity.

My error is given in Unity when trying to build to android, it crashes here.

CommandInvokationFailure: Gradle build failed. 
C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleDebug"

stderr[
D8: Program type already present: com.unity3d.ads.BuildConfig

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForDebug'.

I've tried changing stuff with a build.gradle file like a lot of posts suggest, but I can't get anything to work.

The error didn't exist in Unity 2018.2. I checked right before I updated, but the update is now throwing this issue.

Does anyone have any UNITY specific ideas what to do here? I've tried so many things and nobody's post has been able to help me yet.

Thanks for any help

4 Answers

You can open the PackageManage under Window in the menu bar and remove Advertisement or you can delete the com.unity.ads file of Library/PackageCache in the project directory to resolve this issue.

This error probably happens when you add a library which is not compatible with your compileSdkVersion. In your case you can have libs that were not imported by default by unity (and now are) or there can be a problem with the Build Tools version. (You can try updating them)

I had similar problem a few versions ago, but I don't remember how I fixed it. I didn't have time to upgrade to unity 2018.3 yet. (So the tips are more like guesses, but it may help you solve the issue.)

My settings (Mac):
- Android Studio 2.3
- Unity 2019.1.5f1:
- Player Settings -> Other Settings –> Scripting Runtime Version = .Net 4
- Package Manager -> Advertisement: Uninstalled
- Preferences -> External Tools -> Android: checked Installed with Unity (everything)

My solution:
- delete GoogleMobileAds from project
- delete PlayServicesResolver from project
- delete Plugins from project
- Import Package -> Custom Package -> GoogleMobileAds.unitypackage (3.15.1 in my case)

Related