Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Our response to Improbable’s blog post (and why you can keep working on your SpatialOS game). Read more here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Error when building Android .APK

Discussion in 'Editor & General Support' started by flyinglimousine, Jan 11, 2019 at 7:20 PM.

  1. flyinglimousine

    flyinglimousine

    Joined:
    Jan 9, 2019
    Posts:
    4
    Hi, I'm fairly new to unity, and just experimenting with publishing to android, I am using Unity 2017 4.17f1, JDK 1.8 and the latest Android SDK. I press build, the progress bar nearly reaches the end but then throws up this error:



    It also printed this in the console:

    CommandInvokationFailure: Gradle build failed.
    C:/Program Files/Java/jdk1.8.0_191\bin\java.exe -classpath "D:\Program Files\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.mediation.IUnityAdsExtendedListener

    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:\Documents\Zoom Racing\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\0.jar, D:\Documents\Zoom Racing\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\1.jar, D:\Documents\Zoom Racing\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\2.jar, D:\Documents\Zoom Racing\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\3.jar, D:\Documents\Zoom Racing\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\4.jar, D:\Documents\Zoom Racing\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\5.jar, D:\Documents\Zoom Racing\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\6.jar, D:\Documents\Zoom Racing\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\7.jar, D:\Documents\Zoom Racing\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\8.jar, D:\Documents\Zoom Racing\Temp\gradleOut\build\intermediates\transforms\dexBuilder\release\9.jar
    Program type already present: com.unity3d.ads.mediation.IUnityAdsExtendedListener
    Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

    * 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 35s
    ]
    stdout[
    Starting a Gradle Daemon (subsequent builds will be faster)
    WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
    It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
    :checkReleaseClasspath
    :preBuild UP-TO-DATE
    :preReleaseBuild
    :compileReleaseAidl NO-SOURCE
    :compileReleaseRenderscript
    :checkReleaseManifest
    :generateReleaseBuildConfig
    :prepareLintJar
    :mainApkListPersistenceRelease
    :generateReleaseResValues
    :generateReleaseResources
    :mergeReleaseResources
    :createReleaseCompatibleScreenManifests
    :processReleaseManifest
    :splitsDiscoveryTaskRelease
    :processReleaseResources
    :generateReleaseSources
    :javaPreCompileRelease
    :compileReleaseJavaWithJavac
    :compileReleaseNdk NO-SOURCE
    :compileReleaseSources
    :lintVitalRelease
    :mergeReleaseShaders
    :compileReleaseShaders
    :generateReleaseAssets
    :mergeReleaseAssets
    :transformClassesWithDexBuilderForRelease
    :transformDexArchiveWithExternalLibsDexMergerForRelease FAILED
    21 actionable tasks: 21 executed
    ]
    exit code: 1
    UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1 progress, System.String error)
    UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
    Rethrow as GradleInvokationException: Gradle build failed
    UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
    UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,059
    Does this happen on a new/empty project also?
     
  3. flyinglimousine

    flyinglimousine

    Joined:
    Jan 9, 2019
    Posts:
    4
    Interesting, just tested it and it works fine with an empty project.. I believe it could be something to do with duplicate libraries/assets being imported to my project or something like that? (may have got the word wrong there)
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,059
  5. flyinglimousine

    flyinglimousine

    Joined:
    Jan 9, 2019
    Posts:
    4
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,059
    Correct. We'll need specific steps to reproduce.
     
  7. flyinglimousine

    flyinglimousine

    Joined:
    Jan 9, 2019
    Posts:
    4
    Sorry, I'm not quite sure what you mean.
     
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,059
    Please provide directions how we might see the same behavior in a new project. It doesn't happen in a brand new project, but happens in the larger project. Provide steps to reproduce what you are seeing, starting with an new/empty project.