title: Unity Gradle Build failed while trying to build project as an APK (2019)
body: <p>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: <strong>1 exception was raised by workers: See the console for details.</strong></p>
  
  <p>And then there are 60 Errors in the console.</p>
  
  <p>I already tried to reinstall JDK, the Android Studio, the apk tools in the Unity Hub and i also reinstalled Unity itself (completely).</p>
  
  <p>So, here is the most important Error:</p>
  
  <p>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"</p>
  
  <p>stderr[</p>
  
  <p>FAILURE: Build failed with an exception.</p>
  
  <ul>
  <li><p>What went wrong:
  Execution failed for task ':checkReleaseDuplicateClasses'.</p>
  
  <blockquote>
    <p>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:)</p>
  </blockquote>
  
  <p>Go to the documentation to learn how to Fix dependency resolution errors.</p></li>
  <li><p>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.</p></li>
  <li><p>Get more help at <a href="https://help.gradle.org" rel="nofollow noreferrer">https://help.gradle.org</a></p></li>
  </ul>
  
  <p>BUILD FAILED in 14s
  ]
  stdout[</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>