All of a sudden, Gradle fails to build and throws the following error:
CommandInvokationFailure: Gradle build failed. D:\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath "D:\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
stderr[ D8: Program type already present: com.unity3d.ads.BuildConfig
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForRelease'.
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\0.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\1.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\2.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\3.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\4.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\5.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\6.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\7.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\8.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\9.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\10.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\11.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\12.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\13.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\14.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\15.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\16.jar, D:\Unity Projects\VegOrNonVeg\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\17.jar Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: com.unity3d.ads.BuildConfig
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
I've tried uninstalling the existing SDK and reinstalled SDK for Oreo
I'm also getting the following error: UnityAdsEditor: Initialize(3113808, False); UnityEditor.Advertisements.UnityAdsEditor:EditorOnLoad()
The project had no issues before. No new update or any code changes.
In some cases when your Gradle files are deleted or corrupted you will not be able to download new Gradle files in android studio. In this case, we have to delete the Gradle files which are present already and then again sync your project to download our Gradle files again.
Go to Preferences > External Tools > Android > Gradle, and set the custom Gradle to Gradle 5.6. 4 or later. See Gradle build tool for downloads.
Issue Resolved:
The existing package for Unity Ads was causing this problem.
Go to Package Manager and Remove/Update the Advertisement package (Mine was 2.0.8, updated it to 3.0.3).
Go to Edit > Project Settings > Player and select .NET 4.x Equivalent for the Scripting Runtime Version under Configuration.
If possible choose Minimum API Level as 19 or above.
Make sure to delete the existing Unity Ads folder if present in the Assets Folder of the Project window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With