MacOS cannot build to Android, gradle build failed

Hi,

I am trying to build and run a mobile app project for Android, on my Mac OS machine (Apple Silicon). I keep getting an error related to gradle and java… please see the message below:

CommandInvokationFailure: Gradle build failed. 
/Applications/Unity/Hub/Editor/2022.3.29f1/PlaybackEngines/AndroidPlayer/OpenJDK/bin/java -classpath "/Applications/Unity/Hub/Editor/2022.3.29f1/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-7.2.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

I have tried:

  1. uninstalling Unity,
  2. building on a clean empty project with no success,
  3. installing Android Studio and moving some version of the SDK into the correct path under unity build-tools…

…I am really stumped here. Any advice would be appreciated. Thanks! :innocent:


Some further error logs here

Share entire error log, not headers only

hi @IGuscin :
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not dispatch a message to the daemon.

  • 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

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:203)

@IGuscin

UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action1[T] progress, System.String error) (at <b400cb8c814349078289791bc8e9f3cb>:0) UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, Unity.Android.Gradle.AndroidGradle androidGradle, System.String workingdir, System.String task, System.Action1[T] progress) (at :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 :0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute

(UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:203)

Try updating to the latest available build and checking Preferences → External tools to use all the tools delivered with Unity

@IGuscin they were set to default, I tried uninstalling unity and reinstalling, reinstalling new versions, nothing has worked.

Check “Maximum JVM heap size, Mbyte” in Unity - Manual: Android environment setup, maybe it’s too low, try increasing it

I managed to solve this issue myself after days of grappling !

This article put me on the right track: ESET block Gradle after latest update - ESET Endpoint Products for macOS - ESET Security Forum I have some filters and network proxies set up which I had to remove in order to get gradle to communicate to daemons to run, it seemed my local network connection was being blocked by these restrictions and unable to run gradle builds.

I tried many other things alongside this, which I would recommend to anyone else trying to debug this issue:

  1. Try to build an empty unity project and see if that passes or fails
  2. Check logs in ~/User/Library/Logs/Unity/Editor.log whilst building the project and try to pick up clues from the logs as to what the issue could be.
  3. Ensure Java is installed and recognised on machine by running in a terminal by running java --version , if you do not have a recognised version of java chances are you will need to set up the correct path with a sym link … I followed instructions on the top answer of this stack post: macos - Java/JDK for the Apple Silicon chips - Stack Overflow
  4. Try uninstalling / reinstalling Unity, ensuring all the android add ons are included.
  5. RESTART YOUR MACHINE.
  6. Check for any filters or proxies that could be blocking communication to gradle daemons under System settings > Network > Filters & Proxies , and disable these temporarily whilst building your project.
  7. if you install gradle from homebrew and run it in your terminal with options , gradle build
    –stacktrace, you will get some clues as to what the issue is with gradle, for me it was “cannot send message to gradle daemon” along those lines (as people mention in this stack article gradle - Could not dispatch a message to the daemon - Stack Overflow) …
  8. Installing Android Studio and building out your project in EXPORT mode and trying with the highest SDK could help - also reveal some issues in Android Studio build logs that could set you on the right path.

This was a bitch to resolve but hopefully you can try some of these things and something will point in the right direction if anyone else face this issue. :cry: