'Unity Gradle Build failed while trying to build project as an APK (2019)
I have a really big problem. I wasted many hours with trying to build a little game i made as an APK. I switched the build platform to android, installed the JDK, NDK and SDK tools and it should work. But at the moment when unity is "Building Gradle Prject" an error is poping up: 1 exception was raised by workers: See the console for details.
And then there are 60 Errors in the console.
I already tried to reinstall JDK, the Android Studio, the apk tools in the Unity Hub and i also reinstalled Unity itself (completely).
So, here is the most important Error:
CommandInvokationFailure: Gradle build failed. D:/Unity/2019.2.3f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath "D:\Unity\2019.2.3f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
stderr[
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':checkReleaseDuplicateClasses'.
1 exception was raised by workers: java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class com.unity3d.ads.BuildConfig found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.IUnityAdsListener found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.UnityAds found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.UnityAds$FinishState found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.UnityAds$PlacementState found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.UnityAds$UnityAdsError found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.mediation.IUnityAdsExtendedListener found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.metadata.InAppPurchaseMetaData found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.metadata.MediationMetaData found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.metadata.MetaData found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:) Duplicate class com.unity3d.ads.metadata.PlayerMetaData found in modules classes.jar (:UnityAds:) and classes.jar (:unity-ads:)
Go to the documentation to learn how to Fix dependency resolution errors.
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.
Get more help at https://help.gradle.org
BUILD FAILED in 14s ] stdout[
Task :preBuild UP-TO-DATE Task :preReleaseBuild UP-TO-DATE Task :compileReleaseAidl NO-SOURCE Task :compileReleaseRenderscript NO-SOURCE Task :checkReleaseManifest UP-TO-DATE Task :generateReleaseBuildConfig UP-TO-DATE Task :prepareLintJar UP-TO-DATE Task :generateReleaseSources UP-TO-DATE Task :javaPreCompileRelease UP-TO-DATE Task :mainApkListPersistenceRelease UP-TO-DATE Task :generateReleaseResValues UP-TO-DATE Task :generateReleaseResources UP-TO-DATE Task :mergeReleaseResources UP-TO-DATE Task :createReleaseCompatibleScreenManifests UP-TO-DATE Task :processReleaseManifest Task :processReleaseResources Task :compileReleaseJavaWithJavac UP-TO-DATE Task :compileReleaseSources UP-TO-DATE Task :lintVitalRelease Task :mergeReleaseShaders UP-TO-DATE Task :compileReleaseShaders UP-TO-DATE Task :generateReleaseAssets UP-TO-DATE Task :mergeReleaseAssets Task :validateSigningRelease UP-TO-DATE Task :signingConfigWriterRelease UP-TO-DATE Task :checkReleaseDuplicateClasses FAILED
Solution 1:[1]
I had a similar issue. I found I had enabled the built-in ads extensions option in the ads section of services alongside also having the ads package installed. Uninstalling the ads package in the package manager did the job for me
Solution 2:[2]
it happened to me and I just solve it by commenting-out the unity-ads on gradle dependencies just like that:
//implementation(name: 'unity-ads', ext:'aar')
Solution 3:[3]
I just solved it, basically, the error started when I added the ads Assets from the assets store. what I didn't know that I Had one installed from the package manager there for it was duplicate what you should do is to delete the package from the package manager, because if you delete the folders that were downloaded from the asset store you can't implement the listener in your script.
Solution 4:[4]
I fixed it by going to Assets > Play Services Resolver > Android Resolver > Delete Resolved Libraries
Solution 5:[5]
I've fixed that issue by deleting the playcore.arr file from the Assets/GooglePlayPlugins/com.google.play.core/Runtime/Plugins folder
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alex Clark |
Solution 2 | Sami Alkendi |
Solution 3 | muhamad shara |
Solution 4 | chethanv77777 |
Solution 5 | Frank Eno |