Can't build Android app

Hey guys, I have been trying to fix this for the past 3 days, and just can’t build the app

Unity 2022.3.4f1

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

Environment Variables:
OculusBase = C:\Program Files\Oculus\
USERDOMAIN = DESKTOP-P70H2NO
ProgramFiles = C:\Program Files
TMP = C:\Users\Robert\AppData\Local\Temp
PROCESSOR_ARCHITECTURE = AMD64
PROCESSOR_REVISION = 3c03
OS = Windows_NT
CHROME_CRASHPAD_PIPE_NAME = \\.\pipe\crashpad_18256_VCZDATZMCOUQYOHI
PROCESSOR_IDENTIFIER = Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
ProgramW6432 = C:\Program Files
USERPROFILE = C:\Users\Robert
JAVA_HOME = C:\Program Files\Unity\Hub\Editor\2022.3.4f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK
CommonProgramFiles = C:\Program Files\Common Files
DriverData = C:\Windows\System32\Drivers\DriverData
ComSpec = C:\Windows\system32\cmd.exe
AMPLITUDE_API_KEY = 28f3cae0b33b8b3702120c9ed1a935aa
PSModulePath = C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
ANDROID_NDK_ROOT = C:\Program Files\Unity\Hub\Editor\2022.3.4f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK
SystemRoot = C:\Windows
HEAP_CLIENT_TOKEN = 1717415662
NUMBER_OF_PROCESSORS = 4
AMPLITUDE_API_KEY_STAGING = 83ee04fccc67e4fcc7dd527c4c6f1e21
WOOTRIC_CLIENT_TOKEN = NPS-aa8be4c3
JAVA_TOOL_OPTIONS = -Dfile.encoding=UTF-8
DEBUG_ENV_VAR = UnityHub
BURST_ANDROID_MIN_API_LEVEL = 22
TEMP = C:\Users\Robert\AppData\Local\Temp
Path = C:\Program Files\Oculus\Support\oculus-runtime;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\Robert\AppData\Local\Microsoft\WindowsApps;;E:\Microsoft VS Code\bin
USERNAME = Robert
COMPUTERNAME = DESKTOP-P70H2NO
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
SystemDrive = C:
ALLUSERSPROFILE = C:\ProgramData
SENTRY_ACCESS_TOKEN = 3df78d9e53f8456aa90fbae044ce1a6261421ab1d0014674bc2e933477289017
HEAP_CLIENT_TOKEN_STAGING = 3786794399
windir = C:\Windows
HOMEPATH = \Users\Robert
PUBLIC = C:\Users\Public
CommonProgramFiles(x86) = C:\Program Files (x86)\Common Files
APPDATA = C:\Users\Robert\AppData\Roaming
OneDrive = C:\Users\Robert\OneDrive
PROCESSOR_LEVEL = 6
CommonProgramW6432 = C:\Program Files\Common Files
ProgramFiles(x86) = C:\Program Files (x86)
SESSIONNAME = Console
LOGONSERVER = \\DESKTOP-P70H2NO
LOCALAPPDATA = C:\Users\Robert\AppData\Local
LAUNCH_DARKLY_CLIENT_TOKEN = 60a7e30fafc7e60e33446283
LAUNCH_DARKLY_CLIENT_TOKEN_STAGING = 60a7e30fafc7e60e33446282
HOMEDRIVE = C:
USERDOMAIN_ROAMINGPROFILE = DESKTOP-P70H2NO
ProgramData = C:\ProgramData
ORIGINAL_XDG_CURRENT_DESKTOP = undefined


stderr[
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
C:\Users\Robert\Clicker game\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\Robert\Clicker game\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\Robert\Clicker game\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:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* 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 36s
]
stdout[
Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.4f1\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.4f1\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.4f1\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.4f1\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.4f1\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.4f1\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.4f1\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.4f1\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.4f1\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.4f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only
> 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 :launcher:generateReleaseBuildConfig
> Task :launcher:compileReleaseAidl NO-SOURCE
> Task :launcher:generateReleaseResValues
> Task :launcher:javaPreCompileRelease
> Task :launcher:createReleaseCompatibleScreenManifests
> Task :launcher:extractDeepLinksRelease
> Task :launcher:extractProguardFiles
> Task :launcher:mergeReleaseJniLibFolders
> Task :unityLibrary:mergeReleaseJniLibFolders
> Task :launcher:checkReleaseDuplicateClasses
> Task :launcher:mergeReleaseShaders
> Task :unityLibrary:compileReleaseRenderscript NO-SOURCE
> Task :unityLibrary:generateReleaseBuildConfig
> Task :unityLibrary:generateReleaseResValues
> Task :unityLibrary:generateReleaseResources
> Task :unityLibrary:packageReleaseResources
> Task :unityLibrary:mergeReleaseNativeLibs
> Task :launcher:compileReleaseShaders NO-SOURCE
> Task :launcher:generateReleaseAssets UP-TO-DATE
> Task :launcher:processReleaseJavaRes NO-SOURCE
> Task :launcher:collectReleaseDependencies
> Task :launcher:sdkReleaseDependencyData
> Task :unityLibrary:parseReleaseLocalResources
> Task :launcher:validateSigningRelease
> Task :launcher:writeReleaseAppMetadata
> Task :launcher:writeReleaseSigningConfigVersions
> Task :launcher:desugarReleaseFileDependencies
> Task :launcher:mergeExtDexRelease
> Task :unityLibrary:stripReleaseDebugSymbols
> Task :unityLibrary:javaPreCompileRelease
> Task :unityLibrary:mergeReleaseShaders
> Task :unityLibrary:compileReleaseShaders NO-SOURCE
> Task :unityLibrary:generateReleaseAssets UP-TO-DATE
> Task :unityLibrary:copyReleaseJniLibsProjectAndLocalJars
> Task :unityLibrary:processReleaseManifest
> Task :unityLibrary:packageReleaseAssets
> Task :unityLibrary:packageReleaseRenderscript NO-SOURCE
> Task :unityLibrary:prepareLintJarForPublish
> Task :launcher:mergeReleaseAssets
> Task :launcher:compileReleaseRenderscript NO-SOURCE
> Task :launcher:generateReleaseResources
> Task :unityLibrary:prepareReleaseArtProfile
> Task :unityLibrary:generateReleaseRFile
> Task :unityLibrary:processReleaseJavaRes
> Task :unityLibrary:mergeReleaseJavaResource
> Task :launcher:mergeReleaseArtProfile
> Task :launcher:mergeReleaseResources
> Task :unityLibrary:extractReleaseAnnotations
> Task :launcher:compressReleaseAssets

> Task :unityLibrary:compileReleaseJavaWithJavac

> Task :unityLibrary:compileReleaseJavaWithJavac FAILED
39 actionable tasks: 39 executed
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <b417242467964bd1aa8aad6e355fdf88>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <b417242467964bd1aa8aad6e355fdf88>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <b417242467964bd1aa8aad6e355fdf88>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <b417242467964bd1aa8aad6e355fdf88>: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 <b417242467964bd1aa8aad6e355fdf88>: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 <b417242467964bd1aa8aad6e355fdf88>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <b417242467964bd1aa8aad6e355fdf88>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <b417242467964bd1aa8aad6e355fdf88>:0)
UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)

I’ve had the exact same issue first-time compiling for Android.

I got past the “Probably the SDK is read-only” error by giving all users Full Access to the folder “AndroidPlayer”.
Go to “C:\Program Files\Unity\2022.3.4f1\Editor\Data\PlaybackEngines” in File Explorer.
Right click the folder “AndroidPlayer” and pick “Properties”.
Navigate to the “Security” tab and click “Edit”.
In the list of users on the OS, pick “Users (\Users)” ( will differ based on your PC’s name.)
Tick the box “Full Access” in permissions list below, then Apply.

After some more trial-and-error (Including migrating to 2022.3.5f1, to no avail) I narrowed the issue down to the package “Mobile Notifications”. I disabled it in the Unity Package Manager in my projject and it now builds and the app runs on my phone with no issues.

Im not able to disable this package, unity will reinstall it right away if i remove it from the json file. also in packet manager it is locked.

can you tell me how you did that`?

cheers!

Set target SDK to 33 in player settings.

thanks i try it.

But i wanted to compile for an older android, that means i can only do with older untiy’s then?

You can still compile for older, but you need to use a custom gradle template. By default Unity sets targetSdk and compileSdk to the same value. For your case, you need to set compileSdk manually to 33, while set target sdk to what you want.

Ah now i understand, thank you! Will do like this.
Cheers!

removing Mobile notifications package worked for me right away.

I may be having the same issue, (I’m away from my project atm). What if you need the messaging? I’m using Firebase messaging and my game really needs that for turn notifications.

I found a simple way to solve this issue!
In most cases, you will only need to go to File > Build Settings > Android > Player Settings, and under ‘Minimum API Level,’ select the highest available, like 34 at the time of my writing this.
Then, go to build and run, and you will be prompted with a dialog that will ask you to upgrade the Android API.
Click ‘Upgrade’, and after that, all problems should be solved.
Now, you can build and run with whatever minimum API level you wish.
This solution has worked for the 2022.3.14f1 unity version.

I Solve this error select Minimum API Level and Maximum API Level using and forse resolve.
For max api level -1 and build first time unity install sdk then build.
Preference setting remove and again set then force resolve.
At the end of reset all api level and target level.

Removing the full mobile package (which include notifications) was the fix for me, thanks @neorayb

I still get a compatibility warning but the game start… something is fishy in that mobile package and it might have something to do with Gradle but this is too far from my skillset for me to investigate ^^

Preference setting remove and again set then force resolve.
Try it

Having the same problem on 2021.3.24 lts. Previous version is ok

This worked for me. Thanks a lot!!

This worked for me. Really frustrating though, I hope developers change something in the installation process so it would work out of box.

I got many ANR events in my app, Anr related to GC_Lock. I don’t know how to investigate the Anr, I am looking for a solution I didn’t found.

9692159–1383032–stacktrace.log.txt (111 KB)

Which Unity version are you using, try updating it, because I think this bug was fixed.

2022.3.21f1