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

Bug CommandInvokationFailure: Gradle build failed. 2023.08.09

Discussion in 'Editor & General Support' started by Unitay98, Aug 9, 2023.

  1. Unitay98

    Unitay98

    Joined:
    Aug 9, 2023
    Posts:
    2
    I’ve just installed Unity 2022.3.6f1. Then I tried to compile an empty game, but it failed to build the game. When all the build process is almost completed, it hangs for a while and then throws an error "Gradle build failed, see console for details”. My projects are stored in C:\Users\Public\UnityGames.
    Errors:

    CommandInvokationFailure: Gradle build failed.
    C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-7.2.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleDebug"

    iPcked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    C:\Users\Public\UnityGames\testProject\Library\Bee\Android\Prj\Mono2x\Gradle\unityLibrary\src\main\java\com\unity\androidnotifications\UnityNotificationManager.java:164: error: cannot find symbol
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
    ^
    symbol: variable TIRAMISU
    location: class VERSION_CODES
    C:\Users\Public\UnityGames\testProject\Library\Bee\Android\Prj\Mono2x\Gradle\unityLibrary\src\main\java\com\unity\androidnotifications\UnityNotificationManager.java:165: error: cannot find symbol
    permissionGranted = mContext.checkCallingOrSelfPermission(Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED;
    ^
    symbol: variable POST_NOTIFICATIONS
    location: class permission
    Note: C:\Users\Public\UnityGames\testProject\Library\Bee\Android\Prj\Mono2x\Gradle\unityLibrary\src\main\java\com\unity3d\player\UnityPlayerActivity.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    2 errors
    FAILURE: Build failed with an exception.
    * What went wrong:
    Execution failed for task ':unityLibrary:compileDebugJavaWithJavac'.
    > Compilation failed; see the compiler error output for details.

    AND


    Starting a Gradle Daemon, 2 incompatible and 2 stopped Daemons could not be reused, use --status for details
    Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\32.0.0\package.xml. Probably the SDK is read-only
    Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only
    Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-31\package.xml. Probably the SDK is read-only
    Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-32\package.xml. Probably the SDK is read-only
    Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only
    Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\32.0.0\package.xml. Probably the SDK is read-only
    Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only
    Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-31\package.xml. Probably the SDK is read-only
    Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-32\package.xml. Probably the SDK is read-only
    Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Unfortunately Unity 2022 seems to be strongly overrepresented here as far as reports of issues go.

    Sounds like you have already done the empty project trick, but I'll post my standard checklist and hopefully something in one of the links can be helpful.

    How to troubleshoot build failures:

    First, make a blank project with a single blank scene and prove that it builds successfully. (yes, I realize you said you already did this!)

    If the blank project does NOT build, go fix your Unity installation or your other tools, such as Android SDK, NDK, JDK, etc. It may even be necessary to change to a different version of Unity3D. It is generally best to stay with LTS versions of Unity3D.

    Until you can build a blank project to the target platform, don't fiddle with anything else.

    Once you can build a blank project, now bisect the problem by bringing over parts of your current project and building it one subsystem at a time, perhaps stubbing things out that might trigger compiler errors.

    Most often things that prevent building are third-party libraries such as Firebase.

    Once you identify the subsystem, go to the documentation for it and make sure you are doing it correctly.

    It may also be helpful to work through a tutorial or two for whatever subsystem is making the build fail.

    Android build not building:

    Recently (circa July 2022) there have been reports of Unity's installer failing to install the Android Tools.

    https://forum.unity.com/threads/cant-build-for-android.1306098/

    Here was how I brought up Unity2020.3.41 and the Android SDK 31 on October 30, 2022:

    https://forum.unity.com/threads/aab...y-2021-3-8-with-jdk-1-8.1322211/#post-8551193

    Android Gradle errors and other related stuff:

    https://forum.unity.com/threads/unity-gradle-bug-please-help.1368018/#post-8625789
     
  3. Unitay98

    Unitay98

    Joined:
    Aug 9, 2023
    Posts:
    2
    I think I found a solution for the errors "CommandInvokationFailure: Gradle build failed" and "Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core()"

    STEP 1: Install and manually swap Unity recommended preferences for custom JDK, SDK, NDK, and Gradle.
    Here is a great video I found:


    My settings:
    https://www.flickr.com/photos/198912979@N03/53106446104/in/dateposted-public/

    The video didn't remind me to get the "cmdline-tools" via Android Studio, so remember to get it via Settings > Android SDK > SDK Tools > Android SDK Commaned-line Tools version 8.0.

    https://www.flickr.com/photos/198912979@N03/53106240061/in/dateposted-public/

    STEP 2: You may get an error saying:
    "* What went wrong:
    Could not determine the dependencies of task ':launcher:lintVitalReportRelease'.
    > Could not create task ':launcher:processReleaseMainManifest'.
    > Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method."

    Luckily, I found a great video that showed me that the issue was the version of my gradle. So, download version 7.3.3
     
    Last edited: Aug 10, 2023