Error when trying to compile a build on Android

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

Environment Variables:
USERDOMAIN = DESKTOP-20CD3J1
ProgramFiles = C:\Program Files
TMP = C:\Users\Edes\AppData\Local\Temp
PROCESSOR_ARCHITECTURE = AMD64
PROCESSOR_REVISION = a701
OS = Windows_NT
CHROME_CRASHPAD_PIPE_NAME = \.\pipe\crashpad_16832_EYVRCHUSJASOANRH
PROCESSOR_IDENTIFIER = Intel64 Family 6 Model 167 Stepping 1, GenuineIntel
ProgramW6432 = C:\Program Files
USERPROFILE = C:\Users\Edes
JAVA_HOME = C:\Program Files\Unity\Hub\Editor\2022.3.61f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK
CommonProgramFiles = C:\Program Files\Common Files
DriverData = C:\Windows\System32\Drivers\DriverData
ComSpec = C:\Windows\system32\cmd.exe
PSModulePath = C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
ANDROID_NDK_ROOT = C:\Program Files\Unity\Hub\Editor\2022.3.61f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK
USERNAME = Edes
NUMBER_OF_PROCESSORS = 12
FPS_BROWSER_APP_PROFILE_STRING = Internet Explorer
HOMEDRIVE = C:
TEMP = C:\Users\Edes\AppData\Local\Temp
Path = C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\NVIDIA Corporation\NVIDIA app\NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\160\DTS\Binn;C:\Users\Edes\AppData\Local\Microsoft\WindowsApps;C:\Users\Edes.dotnet\tools
COMPUTERNAME = DESKTOP-20CD3J1
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
ALLUSERSPROFILE = C:\ProgramData
SystemDrive = C:
windir = C:\Windows
FPS_BROWSER_USER_PROFILE_STRING = Default
HOMEPATH = \Users\Edes
PUBLIC = C:\Users\Public
CommonProgramFiles(x86) = C:\Program Files (x86)\Common Files
APPDATA = C:\Users\Edes\AppData\Roaming
OneDrive = C:\Users\вв\OneDrive
PROCESSOR_LEVEL = 6
CommonProgramW6432 = C:\Program Files\Common Files
ProgramFiles(x86) = C:\Program Files (x86)
SystemRoot = C:\Windows
SESSIONNAME = Console
LOGONSERVER = \DESKTOP-20CD3J1
LOCALAPPDATA = C:\Users\Edes\AppData\Local
__COMPAT_LAYER = DetectorsAppHealth
USERDOMAIN_ROAMINGPROFILE = DESKTOP-20CD3J1
ProgramData = C:\ProgramData
ORIGINAL_XDG_CURRENT_DESKTOP = undefined

stderr[

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘C:\Users\Edes\Test\Library\Bee\Android\Prj\Mono2x\Gradle\unityLibrary\build.gradle’ line: 18

  • What went wrong:
    Could not compile build file ‘C:\Users\Edes\Test\Library\Bee\Android\Prj\Mono2x\Gradle\unityLibrary\build.gradle’.

startup failed:
build file ‘C:\Users\Edes\Test\Library\Bee\Android\Prj\Mono2x\Gradle\unityLibrary\build.gradle’: 18: Unexpected input: ‘project(‘mobilenotifications.androidlib’)\n\n}’ @ line 18, column 1.
}
^

1 error

  • 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.

BUILD FAILED in 35s
]
stdout[

Configure project :launcher
WARNING:The option setting ‘android.aapt2FromMavenOverride=C:\Program Files\Unity\Hub\Editor\2022.3.61f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\34.0.0\aapt2.exe’ is experimental.
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at /home/bokken/build/output/unity/unity/PlatformDependent/AndroidPlayer/Editor/Managed/Android/Command.cs:218)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at /home/bokken/build/output/unity/unity/PlatformDependent/AndroidPlayer/Editor/Managed/Android/Command.cs:157)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at /home/bokken/build/output/unity/unity/PlatformDependent/AndroidPlayer/Editor/Managed/Android/Command.cs:116)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action1[T] progress, System.String error) (at /home/bokken/build/output/unity/unity/PlatformDependent/AndroidPlayer/Editor/Managed/Android/AndroidJavaTools.cs:113) UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, Unity.Android.Gradle.AndroidGradle androidGradle, System.String workingdir, System.String task, System.Action1[T] progress) (at /home/bokken/build/output/unity/unity/PlatformDependent/AndroidPlayer/Editor/Managed/Android/Gradle.cs:226)
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 /home/bokken/build/output/unity/unity/PlatformDependent/AndroidPlayer/Editor/Managed/Android/Gradle.cs:231)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at /home/bokken/build/output/unity/unity/PlatformDependent/AndroidPlayer/Editor/Managed/PostProcessor/Tasks/BuildGradleProject.cs:39)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at /home/bokken/build/output/unity/unity/PlatformDependent/AndroidPlayer/Editor/Managed/PostProcessor/AndroidPostProcessor.cs:112)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

CODE build.gradle:
apply plugin: ‘com.android.library’

dependencies {
// Prerequisites
implementation ‘org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72’

// Add if you are using the ShowSafeBrowsing API
implementation 'androidx.browser:browser:1.3.0'
implementation 'androidx.core:core:1.6.0'

}
implementation(name: ‘GpmWebViewPlugin’, ext:‘aar’)
implementation(name: ‘GpmCommunicatorPlugin’, ext:‘aar’)
implementation(name: ‘WebViewPlugin’, ext:‘aar’)
implementation(name: ‘gpm-webview’, ext:‘aar’)
implementation project(‘mobilenotifications.androidlib’)

}

android {
namespace “com.unity3d.player”
ndkPath “C:/Program Files/Unity/Hub/Editor/2022.3.61f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK”
compileSdkVersion 35
buildToolsVersion ‘34.0.0’

compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
}

defaultConfig {
    minSdkVersion 22
    targetSdkVersion 35
    ndk {
        abiFilters 'armeabi-v7a'
    }
    versionCode 1
    versionName '1.0.2'
    consumerProguardFiles 'proguard-unity.txt'
}

lintOptions {
    abortOnError false
}

aaptOptions {
    noCompress = ['.unity3d', '.ress', '.resource', '.obb', '.bundle', '.unityexp'] + unityStreamingAssets.tokenize(', ')
    ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~"
}

packagingOptions {
    doNotStrip '*/armeabi-v7a/*.so'
    jniLibs {
        useLegacyPackaging true
    }
}

}

How to troubleshoot build failures:

Obviously, if there is actionable data, clues or information within any of the errors, fix those problems. Each error entry may have more information than can fit in the console log so select each error and read the expanded view below it.

If that gives you nothing worthwhile (look to Google! You’re never the first one!), then…

First, make a blank project with a single blank scene and prove that it builds successfully.

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 misconfigured or incorrectly-installed or incompatible third-party libraries such as Firebase or AdMob or IronSource.

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:

Circa July 2022 here have been reports of Unity’s installer failing to install the Android Tools.

Here was how I brought up Unity2020.3.41 and the Android SDK 31 on October 30, 2022 (edited on August 23, 2023 to include Android SDK 33…) (and again for SDK34):

Android Gradle errors and other related stuff:

Android SDK35 stuff:

Same problem with unity veersion 2022.61 and firebase 11.6

Same steps to fix. See above.