Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Gradle build failed

Discussion in 'Android' started by Ekeocha, Sep 22, 2023.

  1. Ekeocha

    Ekeocha

    Joined:
    Sep 14, 2020
    Posts:
    12
    Hello
    So I am trying to build an apk in unity 2020.3.3, I have all the sdk, jdk 1.8.0_77 and ndk r19 and I am using the unity Gradle
    But each time I try to build an apk I keep getting an error, I have tried an empty project and also tried modifying my mainTemplate file, but the Gradle keeps looking for dependencies to download, please I need your help to resolve this issue


    CommandInvokationFailure: Gradle build failed.
    C:\Program Files\Java\jdk1.8.0_77\bin\java.exe -classpath "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.6.4.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

    stderr[

    FAILURE: Build failed with an exception.

    * What went wrong:
    A problem occurred configuring project ':launcher'.
    > Could not resolve all artifacts for configuration ':launcher:classpath'.
    > Could not resolve com.android.tools.build:gradle:3.6.0.
    Required by:
    project :launcher
    > Could not resolve com.android.tools.build:gradle:3.6.0.
    > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.6.0/gradle-3.6.0.pom'.
    > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.6.0/gradle-3.6.0.pom'.
    > dl.google.com
    > Could not resolve com.android.tools.build:gradle:3.6.0.
    > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.6.0/gradle-3.6.0.pom'.
    > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.6.0/gradle-3.6.0.pom'.
    > jcenter.bintray.com

    * 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 33s
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    ]
    stdout[
    Starting a Gradle Daemon, 6 incompatible and 2 stopped Daemons could not be reused, use --status for details
    ]
    exit code: 1
    UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    Rethrow as GradleInvokationException: Gradle build failed
    UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
    UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message, System.Exception ex) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <2c6e9a95f1dd4e06ad71afcd2684dcb7>:0)
    UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <c9b5231e365148a4bc210cc4e439206d>:0)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)
     
  2. tduriga

    tduriga

    Joined:
    Dec 9, 2015
    Posts:
    52
    You should really update your Unity version, if you have 2020.3.3 installed, then you should update to at least 2020.3.15 because there was an update to the gradle plugin from that version (source: Unity - Manual: Gradle for Android (unity3d.com)). Latest minor version is 2020.3.48 so you are really behind.

    Second issue is that you have jcenter() in your gradle repositories, which is deprecated. If you can't find it in your template then you probably need to look inside ""C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates" and replace jcenter() with
    mavenCentral().

    Another issue is that according to the table inside Unity Manual (link above), the Gradle plugin 5.6.4 should have Android Gradle Plugin 4.0.1 for Unity versions from 2020.3.1 up to 2020.3.14. But it seems that you are requesting version 3.6.0. You probably upgraded to the 2020.3.3 from earlier Unity version and forgot to update your gradle templates.
     
  3. Ekeocha

    Ekeocha

    Joined:
    Sep 14, 2020
    Posts:
    12
    Hello and thank you for your reply, I will update it and post my results here, thank you so much
     
  4. Ekeocha

    Ekeocha

    Joined:
    Sep 14, 2020
    Posts:
    12
    Hello so I updated to 2020.3.35
    And I used internet connection to build my apk under development build
    And it built my apk just fine
    But when I unticked it

    I got this new error


    CommandInvokationFailure: Gradle build failed.
    C:\Program Files\Java\jdk1.8.0_77\bin\java.exe -classpath "C:\Program Files\Unity 2020.3.35f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

    stderr[
    Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
    Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
    Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
    Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
    Warning: unexpected element (uri:"", local:"extension-level"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
    Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':launcher:processReleaseResources'.
    > Could not resolve all files for configuration ':launcher:_internal_aapt2_binary'.
    > Failed to transform aapt2-4.0.1-6197926-windows.jar (com.android.tools.build:aapt2:4.0.1-6197926) to match attributes {artifactType=_internal-android-aapt2-binary, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
    > Execution failed for Aapt2Extractor: C:\Users\VICTOR\.gradle\caches\modules-2\files-2.1\com.android.tools.build\aapt2\4.0.1-6197926\5fb49c160d0110a829e15627a8f46ce2dc077664\aapt2-4.0.1-6197926-windows.jar.
    > Failed to create directory 'C:\Users\VICTOR\.gradle\caches\transforms-2\files-2.1\191c94df5fd2d7bdfb73b3f75afa22c0\aapt2-4.0.1-6197926-windows'

    * 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 2m 9s
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    ]
    stdout[
    Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details

    > Configure project :launcher
    WARNING: The option setting 'android.enableR8=false' is deprecated.
    It will be removed in version 5.0 of the Android Gradle plugin.
    You will no longer be able to disable R8

    > Task :unityLibrary:preBuild UP-TO-DATE
    > Task :launcher:preBuild UP-TO-DATE
    > Task :launcher:preReleaseBuild UP-TO-DATE
    > Task :unityLibrary:preReleaseBuild UP-TO-DATE
    > Task :unityLibrary:compileReleaseAidl NO-SOURCE
    > Task :unityLibrary:packageReleaseRenderscript NO-SOURCE
    > Task :unityLibrary:compileReleaseRenderscript NO-SOURCE
    > Task :unityLibrary:generateReleaseResValues UP-TO-DATE
    > Task :unityLibrary:generateReleaseResources UP-TO-DATE
    > Task :launcher:generateReleaseBuildConfig UP-TO-DATE
    > Task :launcher:compileReleaseAidl NO-SOURCE
    > Task :launcher:compileReleaseRenderscript NO-SOURCE
    > Task :launcher:javaPreCompileRelease UP-TO-DATE
    > Task :launcher:generateReleaseResValues UP-TO-DATE
    > Task :launcher:generateReleaseResources UP-TO-DATE
    > Task :launcher:createReleaseCompatibleScreenManifests UP-TO-DATE
    > Task :launcher:extractDeepLinksRelease UP-TO-DATE
    > Task :launcher:prepareLintJar UP-TO-DATE
    > Task :unityLibrary:packageReleaseResources UP-TO-DATE
    > Task :unityLibrary:extractDeepLinksRelease UP-TO-DATE
    > Task :launcher:checkReleaseDuplicateClasses
    > Task :launcher:mergeReleaseResources UP-TO-DATE
    > Task :unityLibrary:compileReleaseLibraryResources UP-TO-DATE
    > Task :unityLibrary:parseReleaseLocalResources UP-TO-DATE
    > Task :unityLibrary:generateReleaseBuildConfig UP-TO-DATE
    > Task :unityLibrary:javaPreCompileRelease UP-TO-DATE
    > Task :unityLibrary:prepareLintJarForPublish UP-TO-DATE
    > Task :unityLibrary:processReleaseManifest
    > Task :launcher:processReleaseManifest
    > Task :unityLibrary:generateReleaseRFile UP-TO-DATE
    > Task :launcher:processReleaseResources FAILED
    > Task :launcher:desugarReleaseFileDependencies
    21 actionable tasks: 5 executed, 16 up-to-date
    ]
    exit code: 1
    UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <b6530713c8564225834b4768bc10f776>:0)
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <b6530713c8564225834b4768bc10f776>:0)
    UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <b6530713c8564225834b4768bc10f776>:0)
    UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <b6530713c8564225834b4768bc10f776>:0)
    UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <b6530713c8564225834b4768bc10f776>:0)
    Rethrow as GradleInvokationException: Gradle build failed
    UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <b6530713c8564225834b4768bc10f776>:0)
    UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <b6530713c8564225834b4768bc10f776>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <b6530713c8564225834b4768bc10f776>:0)
    Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
    UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message, System.Exception ex) (at <b6530713c8564225834b4768bc10f776>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <b6530713c8564225834b4768bc10f776>:0)
    UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <b6530713c8564225834b4768bc10f776>:0)
    UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <b6530713c8564225834b4768bc10f776>:0)
    UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <bfe26bbc7be749c7bb22d52435e15888>:0)

    Any help?
     
  5. tduriga

    tduriga

    Joined:
    Dec 9, 2015
    Posts:
    52
    1. Are you using Android SDK, NDK etc. that is bundled with the Unity? If not then try to build with the bundled versions.
    2. Try to build apk from clean project, if it works then it is configuration problem.
    3. Try to disable minify/proguard.
    4. Disable your custom gradle templates/properties.

    If any of the above works, then you will be closer to finding the issue.
     
  6. Ekeocha

    Ekeocha

    Joined:
    Sep 14, 2020
    Posts:
    12

    In the number one u wrote, what do you mean by bundled version
     
  7. tduriga

    tduriga

    Joined:
    Dec 9, 2015
    Posts:
    52
    You can find it inside Preferences>External Tools. upload_2023-9-25_15-58-32.png