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

Can't build my project to android(Gradle Build Failed)

Discussion in 'Android' started by unity_Ixu_VnfhPS3FCw, Jan 12, 2022.

  1. unity_Ixu_VnfhPS3FCw

    unity_Ixu_VnfhPS3FCw

    Joined:
    Dec 3, 2021
    Posts:
    3
    Hi,
    Everytime i try to build my project to android, i get these errors:


    1. FAILURE: Build failed with an exception.
      * Where:
      Build file 'C:\Users\aliro\Documents\test\Library\Bee\Android\Prj\Mono2x\Gradle\launcher\build.gradle' line: 1
      * What went wrong:
      A problem occurred evaluating project ':launcher'.
      > Could not initialize class com.android.build.gradle.internal.crash.PluginCrashReporter
      * 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
      Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
      UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

    2. CommandInvokationFailure: Gradle build failed.
      C:\Program Files\Unity\Hub\Editor\2021.2.7f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2021.2.7f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
      stderr[
      FAILURE: Build failed with an exception.
      * Where:
      Build file 'C:\Users\aliro\Documents\test\Library\Bee\Android\Prj\Mono2x\Gradle\launcher\build.gradle' line: 1
      * What went wrong:
      A problem occurred evaluating project ':launcher'.
      > Could not initialize class com.android.build.gradle.internal.crash.PluginCrashReporter
      * 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
      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 <374d68101b9e4829844c8329406f32cc>:0)
      UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <374d68101b9e4829844c8329406f32cc>:0)
      UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <374d68101b9e4829844c8329406f32cc>:0)
      UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <374d68101b9e4829844c8329406f32cc>:0)
      UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, Unity.Android.Gradle.AndroidGradle androidGradle, System.String workingdir, System.String task, System.Action`1[T] progress) (at <374d68101b9e4829844c8329406f32cc>:0)
      Rethrow as GradleInvokationException: Gradle build failed
      UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, Unity.Android.Gradle.AndroidGradle androidGradle, System.String workingdir, System.String task, System.Action`1[T] progress) (at <374d68101b9e4829844c8329406f32cc>:0)
      UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <374d68101b9e4829844c8329406f32cc>:0)
      UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <374d68101b9e4829844c8329406f32cc>: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 <374d68101b9e4829844c8329406f32cc>:0)
      UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <374d68101b9e4829844c8329406f32cc>:0)
      UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, AndroidPlayerBuildProgram.Data.AndroidPlayerBuildProgramOutput buildProgramOutput) (at <374d68101b9e4829844c8329406f32cc>:0)
      UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <374d68101b9e4829844c8329406f32cc>:0)
      UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.Int32 subtarget, 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 <0cde216a590a4d6fbc3d7db7ac203c5d>:0)
      UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)

    3. Build completed with a result of 'Failed' in 392 seconds (392218 ms)
      UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

    4. UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
      at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002d8] in <0cde216a590a4d6fbc3d7db7ac203c5d>:0
      at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <0cde216a590a4d6fbc3d7db7ac203c5d>:0
      UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

    The minimum Api Level is 22 and target api is level 30 and i don't have any ads networks.
    Please help
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
  3. unity_Ixu_VnfhPS3FCw

    unity_Ixu_VnfhPS3FCw

    Joined:
    Dec 3, 2021
    Posts:
    3
    I deleted .android folder but i'm still getting the same errors.
    And i got this warning:
    Unable to find player assembly: C:\Users\aliro\Documents\test\Temp\StagingArea\Data\Managed\UnityEngine.TestRunner.dll
    UnityEngine.Debug:LogWarning (object)
    Unity.Burst.Editor.BurstAotCompiler:OnPostBuildPlayerScriptDLLsImpl (UnityEditor.Build.Reporting.BuildReport) (at Library/PackageCache/com.unity.burst@1.6.0/Editor/BurstAotCompiler.cs:328)
    Unity.Burst.Editor.BurstAotCompiler:OnPostBuildPlayerScriptDLLs (UnityEditor.Build.Reporting.BuildReport) (at Library/PackageCache/com.unity.burst@1.6.0/Editor/BurstAotCompiler.cs:186)
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    Does this happen with empty project too? You could try to delete project's library folder (backup first)
     
  5. unity_Ixu_VnfhPS3FCw

    unity_Ixu_VnfhPS3FCw

    Joined:
    Dec 3, 2021
    Posts:
    3
    Yes it happens with empty project.
    I deleted the project's library folder but it didn't work..
     
  6. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    I think I'm having the same problem with 2021.2.8f1. I'm not sure when it broke but it works with 2021.2.3f1.

    It looks like the adb daemon keeps crashing for some reason. Screen Shot 2022-01-15 at 18.18.33.png

    I also posted some logs here.
     
  7. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    Try creating Android project from Android Studio, and see if the same happens
     
  8. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    The error means you're using two or more different adb processes from different locations on disk, so they keep killing each other.
     
  9. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    As far as I can see there's only one adb running and it's the one from 2021.2.8f1 which I've added to my PATH.
     
  10. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    I think it's just crashing. If you open a shell or try to install an apk the process ends in seconds.

    If I run adb from 2021.2.3f1 then it works fine.
     
  11. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    You shouldn't need to add adb location to PATH, that's basically asking for trouble. Since different Unity versions will have different adb depending which SDK is set.
     
  12. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    I don't know I've never had issues with that before. I'm mostly using one Unity version at a time and when I need to work on an older project I change the path to point to that version (path config). It's also necessary because some third party plugins use the SDK directly and I want everything to use the same version.

    In any case, I removed the SDK from the path and it still fails to install the apk to the device when trying to make an Android build. If I check with ps in the terminal after the build fails I don't see any adb sever running.

    And I just realized this is a different problem from OP, but posting my logs just in case it's related.

    Code (CSharp):
    1. CommandInvokationFailure: Unable to install APK to device. Please make sure the Android SDK is installed and is properly configured in the Editor. See the Console for more details.
    2. /Applications/Unity/Hub/Editor/2021.2.8f1/PlaybackEngines/AndroidPlayer/SDK/platform-tools/adb -s "ce0517157389ae1f02" install -r -d "/Users/spacepluk/Desktop/vikings/build-android.apk"
    3.  
    4. stderr[
    5. adb: failed to install /Users/spacepluk/Desktop/vikings/build-android.apk:
    6. ]
    7. stdout[
    8. Performing Streamed Install
    9. ]
    10. exit code: 1
    11. UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    12. UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    13. UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    14. UnityEditor.Android.ADB.RunInternal (System.String[] command, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    15. UnityEditor.Android.ADB.Run (System.String[] command, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    16. UnityEditor.Android.AndroidDevice.Exec (System.String[] command, System.String errorMsg) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    17. UnityEditor.Android.AndroidDevice.Install (System.String apkfile) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    18. UnityEditor.Android.AndroidDeploymentTargetsExtension+<>c__DisplayClass17_0.<UploadAPK>b__0 () (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    19. UnityEditor.Android.AndroidDeploymentTargetsExtension.UploadAPK (UnityEditor.Android.AndroidBuildProperties buildProperties, UnityEditor.Android.AndroidDevice device, UnityEditor.Android.AndroidDeploymentTargetsExtension+LaunchProgressTaskManager taskManager) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    20. UnityEditor.Android.AndroidDeploymentTargetsExtension+<>c__DisplayClass13_1.<LaunchBuildOnTarget>b__2 () (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    21. UnityEditor.ProgressTaskManager.Run () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Utils/ProgressBarUtils.cs:71)
    22. UnityEditor.Android.AndroidDeploymentTargetsExtension.LaunchBuildOnTarget (UnityEditor.DeploymentTargets.IDeploymentTargetsMainThreadContext context, UnityEditor.BuildProperties buildProperties, UnityEditor.DeploymentTargets.DeploymentTargetId targetId, UnityEditor.ProgressHandler progressHandler) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    23. UnityEditor.DeploymentTargets.DeploymentTargetManager.LaunchBuildOnTarget (UnityEditor.BuildProperties buildProperties, UnityEditor.DeploymentTargets.DeploymentTargetId targetId, UnityEditor.ProgressHandler progressHandler) (at /Users/bokken/buildslave/unity/build/Editor/Mono/DeploymentTargets/DeploymentTargetManager.cs:45)
    24. UnityEditor.PostprocessBuildPlayer+<>c__DisplayClass22_1.<LaunchOnTargets>b__1 () (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:283)
    25. UnityEditor.ProgressTaskManager.Run () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Utils/ProgressBarUtils.cs:71)
    26. UnityEditor.PostprocessBuildPlayer.LaunchOnTargets (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget buildTarget, UnityEditor.Build.Reporting.BuildReport buildReport, System.Collections.Generic.List`1[T] launchTargets) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:302)
    27. UnityEditor.Android.PostProcessAndroidPlayer.Launch (UnityEditor.BuildTarget target, System.String installPath, UnityEditor.Build.Reporting.BuildReport report) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    28. UnityEditor.Android.AndroidBuildPostprocessor.LaunchPlayer (UnityEditor.Modules.BuildLaunchPlayerArgs args) (at <7d63e054662d4a66a7ebdbe51d59ae2c>:0)
    29. UnityEditor.PostprocessBuildPlayer.Launch (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget buildTarget, System.String path, System.String productName, UnityEditor.BuildOptions options, UnityEditor.Build.Reporting.BuildReport buildReport) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:246)
    30. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)
    31.  
     
  13. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    Not sure what's wrong here, try deleting existing app on the phone if such exist, check if there's enough space, etc.
     
  14. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    I've already tried but it didn't help. I've also tried on several different devices with the same result. From what I can see, it looks like the adb server in 2021.2.8f1 is crashing/terminating shortly after it starts.
     
  15. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    Could you try deploying via Android Studio? And if it works, configure Android Studio to use the Android SDK which is used by Unity and see if it works then.

    Alternatively, install https://docs.unity3d.com/Packages/com.unity.mobile.android-logcat@0.1/manual/index.html , there's a menu item inside to open terminal, after terminal opens, manually do adb install <path_to_apk> and see if it works when done manually.
     
  16. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    A fresh install of Android Studio has the same issues when testing with a basic activity project and the sdk that gets installed by default (platform-tools 31.0.3).

    I can see in the logs that adb keeps restarting. Also back in Unity the logcat window shows some logs from the device and then it disconnects almost immediately (after a second or so). Also trying to install the apk manually from the terminal doesn't work because it gets interrupted when adb dies.

    I replaced the platform-tools folder in Android Studio's SDK with the one that was shipped with 2021.2.3f1 (28.0.1 according to sdkmanager) and that works as expected. I did the same with the SDK included in 2021.2.8f1 and that seems to be doing the trick for now but it doesn't seem like the best solution.

    I couldn't find any way to download specific versions of platform-tools from google so I can't test which version introduced the problem.
     
  17. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    As mentioned previously, disconnection means that adb from two different locations on your PC are being started. Maybe you have some Android Tool (like Monitor) or GPU profiler running which is constantly querying adb?
     
  18. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    I've discarded that already. I'm only running one app at a time and I've checked with ps on the terminal to make sure only one is running. You also get a message from adb when there's a different version running and I'm not seeing that here.
     
  19. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    Another test that I think discards that option.

    1. Check with ps that no adb is running
    2. Launch Android Studio (with the replaced platform-tools 28.0.1)
    3. Check that adb is running (it is, and it works).
    4. Upgrade to the latest version of platform-tools with the sdk manager GUI
    5. adb starts with the disconnection loop and the problems start.

    Screen Shot 2022-01-16 at 16.31.39.png
     
  20. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    I can also reproduce the issue when launching the adb server in isolation from the terminal.
    And it works with the older version of platform-tools.

    Code (CSharp):
    1. ~ ps ax | grep -i adb
    2. 22383 s000  S+     0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox -i adb
    3. ~
    4. ~ ~/Library/Android/sdk/platform-tools/adb start-server
    5. * daemon not running; starting now at tcp:5037
    6. * daemon started successfully
    7. ~
    8. ~
    9. ~ ps ax | grep -i adb
    10. 22410 s000  R+     0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox -i adb
    11. ~
    12. ~
    13. ~ /Applications/Unity/Hub/Editor/2021.2.3f1/PlaybackEngines/AndroidPlayer/SDK/platform-tools/adb start-server
    14. * daemon not running; starting now at tcp:5037
    15. * daemon started successfully
    16. ~
    17. ~ ps ax | grep -i adb
    18. 22428   ??  Ss     0:00.05 adb -L tcp:5037 fork-server server --reply-fd 4
    19. 22437 s000  S+     0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox -i adb
    20. ~
    21.  
    22.  
     
    Last edited: Jan 16, 2022