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

Compile error on Android Platform

Discussion in 'Editor & General Support' started by Bagazi, Mar 14, 2021.

  1. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    609
    I got a compiling error on android platform with Unity 2020.2.7f1c1 (64-bit)... Is there anyway to slove it?


    CommandInvokationFailure: Gradle build failed.
    C:\Program Files\Unity\Hub\Editor\2020.2.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2020.2.7f1c1\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'. Received status code 400 from server: Bad Request
    > 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'. Received status code 400 from server: Bad Request

    * 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 1s
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    ]
    stdout[

    ]
    exit code: 1
    UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <5cf84f2cc5134566935b135856517214>:0)
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <5cf84f2cc5134566935b135856517214>:0)
    UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <5cf84f2cc5134566935b135856517214>:0)
    UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <5cf84f2cc5134566935b135856517214>:0)
    UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <5cf84f2cc5134566935b135856517214>: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 <5cf84f2cc5134566935b135856517214>:0)
    UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <5cf84f2cc5134566935b135856517214>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <5cf84f2cc5134566935b135856517214>: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 <5cf84f2cc5134566935b135856517214>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <5cf84f2cc5134566935b135856517214>: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 <5cf84f2cc5134566935b135856517214>:0)
    UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <5cf84f2cc5134566935b135856517214>: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 <439f491f7d8844bea7734598426775aa>:0)
    UnityEditor.EditorApplication:Internal_CallGlobalEventHandler()
     
  2. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    609
    upload_2021-3-14_13-11-19.png


    I export android project , it looks like the build.gradle version was 3.6.0, but according to the Unity document ,the gradle version would be 5.6.4 on 2020 version of Unity..

    Did I miss something? :confused:Or should I manually modify some configuration? By the way, I have installed serval Unity versions via Unity hub..

    upload_2021-3-14_13-14-7.png
     
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    There is gradle version and there is gradle plugin for android version.
    Do you use Gradle that comes with Unity or custom install?
     
  4. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    609
    Yeah , I used the default version .
    upload_2021-3-15_17-45-6.png

    And I have tried the custom one ,but does not work..
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    Does a new empty Unity project builds fine?
    Such build errors can happen when using custom gradle templates that aren't compatible with the used gradle version.
     
  6. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    609
    I remembered I have installed elder version of Unity which I removed it by uninstall. Is that could be the cause?:confused:
     
  7. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    That possible, try unticking the gradle setting and look at the path it points to.
    But does your project uses gradle templates?
     
  8. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    609
    I used the default gradle first until I got the error, so I try to modify the gradle template but does not work. Now I change it back.





    // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN

    allprojects {
    buildscript {
    repositories {**ARTIFACTORYREPOSITORY**
    google()
    jcenter()


    }

    dependencies {
    // If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity
    // See which Gradle version is preinstalled with Unity here https://docs.unity3d.com/Manual/android-gradle-overview.html
    // See official Gradle and Android Gradle Plugin compatibility table here https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
    // To specify a custom Gradle version in Unity, go do "Preferences > External Tools", uncheck "Gradle Installed with Unity (recommended)" and specify a path to a custom Gradle version
    // classpath 'com.android.tools.build:gradle:5.1.1'
    **BUILD_SCRIPT_DEPS**
    }
    }

    repositories {**ARTIFACTORYREPOSITORY**
    google()
    jcenter()
    flatDir {
    dirs "${project(':unityLibrary').projectDir}/libs"
    }
    }
    }

    task clean(type: Delete) {
    delete rootProject.buildDir
    }


    This is the baseProjectTemplate under the Unity sdk "C:\Program Files\Unity\Hub\Editor\2020.2.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates" (In my case )

    Is it normal and correct? And I only have modified this file .
     
  9. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    609
    I got an error on new Project ,still about gradle but different..

    CommandInvokationFailure: Gradle build failed.
    C:\Program Files\Unity\Hub\Editor\2020.2.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2020.2.7f1c1\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.

    * Where:
    Build file 'D:\WorkSpace\Test\TestAndroid\TestAndroid\Temp\gradleOut\launcher\build.gradle' line: 3

    * What went wrong:
    A problem occurred evaluating project ':launcher'.
    > Plugin with id 'com.android.application' not found.

    * 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 1s
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    ]
    stdout[

    ]
    exit code: 1
    UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <53eba1e5422a4c52b9cf57c0e90cf697>:0)
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <53eba1e5422a4c52b9cf57c0e90cf697>:0)
    UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <53eba1e5422a4c52b9cf57c0e90cf697>:0)
    UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <53eba1e5422a4c52b9cf57c0e90cf697>:0)
    UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <53eba1e5422a4c52b9cf57c0e90cf697>: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 <53eba1e5422a4c52b9cf57c0e90cf697>:0)
    UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <53eba1e5422a4c52b9cf57c0e90cf697>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <53eba1e5422a4c52b9cf57c0e90cf697>: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 <53eba1e5422a4c52b9cf57c0e90cf697>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <53eba1e5422a4c52b9cf57c0e90cf697>: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 <53eba1e5422a4c52b9cf57c0e90cf697>:0)
    UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <53eba1e5422a4c52b9cf57c0e90cf697>: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 <e66c699003e54995bfda53d67e9d180c>:0)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)
     
  10. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    You should never modify gradle templates in "C:\Program Files\Unity\Hub\Editor\2020.2.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates" because that will affect all of the projects made with that Unity version. Instead you should overwrite gradle template inside of the project and then modify it instead. Based on your issues it seems that your project already has some gradle templates overwritten. First revert any changes you have done in Unity install directory, then open your project, in the top menu choose "Edit" -> "Project Settings...", then click on the "Player" tab and go to the "Publishing Settings" section. Check if any templates are overwritten. Most likely they will be and will be specifying to use android gradle plugin version 3.6.0. As for the second error, do you get it in a totally empty project created with Unity 2020.2.7f1 or in a project created with some older Unity version and then opened in Unity 2020.2? That error makes it look like something is not configured right and it should not happen with an empty project. So either you have opened an older project (in that case you have to recreate gradle build files based on the templates in Unity 2020.2), or you have done some modifications in templates included in the Unity install directory (in which case you should revert those changes or if uncertain of what was changed, just reinstall Unity to be safe)
     
    Last edited: Mar 15, 2021
  11. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    By the way, this is the settings block which allows to overwrite gradle files in the project:
    upload_2021-3-15_14-29-50.png
     
  12. Ekeocha

    Ekeocha

    Joined:
    Sep 14, 2020
    Posts:
    12
    Please could you elaborate more
    I have the same error as the first
    I use unity 2020.3.3
    And I tried creating a new project too