Unable to Build Unity Project for Android - Gradle Errors and Dependency Issues

Hello everyone,

I am completely stuck and unable to build my Unity project for Android. I’ve tried absolutely every solution I could find on the internet, but nothing seems to work. Here are the details:

1 -

Configure project :unityLibrary
Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘maven2’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘MavenLocal’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘MavenRepo’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘maven2’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘MavenLocal’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘MavenRepo’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘maven2’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘MavenLocal’ was added by build file ‘unityLibrary/build.gradle’
Build was configured to prefer settings repositories over project repositories but repository ‘MavenRepo’ was added by build file ‘unityLibrary/build.gradle’

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/Users/myname/Documents/Assets/myproject/Library/Bee/Android/Prj/IL2CPP/Gradle/unityLibrary/build.gradle' line: 20

* What went wrong:
A problem occurred evaluating project ':unityLibrary'.
> Could not find method androidx.lifecycle:lifecycle-common-java8:2.4.1() for arguments [build_5fl2ncmm5uwtucdqlezeunaud$_run_closure2$_closure9@448bfc01] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':unityLibrary'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

* 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 840ms

UnityEditor.BuildPlayerWindow/DefaultBuildMethods:BuildPlayer (UnityEditor.BuildPlayerOptions)
Naninovel.BuildProcessor:BuildPlayer (UnityEditor.BuildPlayerOptions) (at Assets/Naninovel/Editor/Build/BuildProcessor.cs:45)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:219)
CommandInvokationFailure: Gradle build failed. 
/Users/myname/VersionUnity/2023.2.20f1/PlaybackEngines/AndroidPlayer/OpenJDK/bin/java -classpath "/Users/myname/VersionUnity/2023.2.20f1/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-7.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

Environment Variables:
DEBUG_ENV_VAR = UnityHub
XPC_FLAGS = 0x0
__CFBundleIdentifier = com.unity3d.unityhub
AMPLITUDE_API_KEY_GREENBUCKET_DEV = 3ded2a762163603391a425f688f990c8
AMPLITUDE_TOKEN_REDBUCKET_DEV = U4PSN7S7PuYVRODivvdcFwbu8R6IHGqa
SECURITYSESSIONID = 186a3
AMPLITUDE_API_KEY_GREENBUCKET_PROD = c86fea37a9e1d3f0878b96e15b111c7c
SENTRY_ACCESS_TOKEN = 3df78d9e53f8456aa90fbae044ce1a6261421ab1d0014674bc2e933477289017
JAVA_HOME = /Users/myname/VersionUnity/2023.2.20f1/PlaybackEngines/AndroidPlayer/OpenJDK
AMPLITUDE_DEPLOYMENT_KEY_RED_BUCKET_DEV = client-wbjHYrmeSR87GmWOE7LDpf7sUySOIKHm
AMPLITUDE_TOKEN_GREENBUCKET_PROD = ZpUcbAdZXJYzNSoHsAWtL_s_JppwWid9
AMPLITUDE_API_KEY = 28f3cae0b33b8b3702120c9ed1a935aa
XPC_SERVICE_NAME = application.com.unity3d.unityhub.163560910.163560916
ANDROID_NDK_ROOT = /Users/myname/VersionUnity/2023.2.20f1/PlaybackEngines/AndroidPlayer/NDK
AMPLITUDE_API_KEY_STAGING = 83ee04fccc67e4fcc7dd527c4c6f1e21
WOOTRIC_CLIENT_TOKEN = NPS-aa8be4c3
USER = myname
MallocNanoZone = 0
LOGNAME = myname
__CF_USER_TEXT_ENCODING = 0x1F5:0x0:0x1
AMPLITUDE_API_KEY_YELLOWBUCKET_DEV = 48835b4d1f5e342aefe5f016324d296a
PATH = /usr/bin:/bin:/usr/sbin:/sbin
LaunchInstanceID = 1E060FF6-1546-480B-BB39-8505AE1EB0C9
SSH_AUTH_SOCK = /private/tmp/com.apple.launchd.okTzCIZxMi/Listeners
AMPLITUDE_API_KEY_YELLOWBUCKET_PROD = e03a9bbe92dc38a88cdb068d24c65b46
AMPLITUDE_TOKEN_REDBUCKET_PROD = jTIgKs5KTZOjiqEEVdZFbgo_VRhABduL
AMPLITUDE_TOKEN_YELLOWBUCKET_PROD = UYDQtPOw83dIfVy3SrW5oMyo7ru4PRkV
HOME = /Users/myname
TMPDIR = /var/folders/cw/nt3dqwxd7r99tbq28txkrfkw0000gn/T/
ORIGINAL_XDG_CURRENT_DESKTOP = undefined
AMPLITUDE_TOKEN_GREENBUCKET_DEV = 84H2gMm_FJzhr3mBaX1lM1JVukmCM7d9
AMPLITUDE_TOKEN_YELLOWBUCKET_DEV = wKi8foVigDditGFvmZewRFWsEbX9Y0YO
SHELL = /bin/bash
AMPLITUDE_API_KEY_REDBUCKET_PROD = ca12bb461ea96f9bdf5df4ded7d52994
AMPLITUDE_DEPLOYMENT_KEY_RED_BUCKET_PROD = client-zH8Y7OK1i331EKuG77C6UxN8ygcM6LzS
COMMAND_MODE = unix2003
AMPLITUDE_API_KEY_REDBUCKET_DEV = 46b8b46515e7632fc42a504b72e05fd0


stderr[

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/Users/myname/Documents/Assets/myproject/Library/Bee/Android/Prj/IL2CPP/Gradle/unityLibrary/build.gradle' line: 20

* What went wrong:
A problem occurred evaluating project ':unityLibrary'.
> Could not find method androidx.lifecycle:lifecycle-common-java8:2.4.1() for arguments [build_5fl2ncmm5uwtucdqlezeunaud$_run_closure2$_closure9@448bfc01] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':unityLibrary'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

* 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 840ms
]
stdout[

> Configure project :unityLibrary
Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'maven2' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'MavenLocal' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'maven2' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'MavenLocal' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'maven2' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'MavenLocal' was added by build file 'unityLibrary/build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by build file 'unityLibrary/build.gradle'
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <0494c3641848448e94810128540ecc93>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <0494c3641848448e94810128540ecc93>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg, System.Text.Encoding inputEncoding) (at <0494c3641848448e94810128540ecc93>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <0494c3641848448e94810128540ecc93>: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 <0494c3641848448e94810128540ecc93>: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 <0494c3641848448e94810128540ecc93>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <0494c3641848448e94810128540ecc93>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <0494c3641848448e94810128540ecc93>:0)
UnityEditor.DefaultBuildMethods:BuildPlayer(BuildPlayerOptions)
Naninovel.BuildProcessor:BuildPlayer(BuildPlayerOptions) (at Assets/Naninovel/Editor/Build/BuildProcessor.cs:45)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:219)


Build completed with a result of 'Failed' in 11 seconds (11314 ms)
3 errors
UnityEditor.BuildPlayerWindow/DefaultBuildMethods:BuildPlayer (UnityEditor.BuildPlayerOptions)
Naninovel.BuildProcessor:BuildPlayer (UnityEditor.BuildPlayerOptions) (at Assets/Naninovel/Editor/Build/BuildProcessor.cs:45)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:219)

What I’ve already tried:

  1. Clearing the cache: Deleted the Library and Temp folders.
  2. Adjusting SDK versions: Tried different values for compileSdkVersion, targetSdkVersion, and even the Android Gradle Plugin version.
  3. Force Resolving external dependencies in Unity.
  4. Toggling Player Settings: Checked/unchecked Custom Main Gradle Template, modified minSdkVersion and buildToolsVersion.
  5. Creating an empty Unity project: No issues on a fresh project, but as soon as I work on this one, the build fails.

My Environment:

Unity version: 2023.2.20f1
Gradle version: 7.6 (provided by Unity)
Android Gradle Plugin: 7.3.1
SDK/NDK: Default version provided by Unity with API 33

What I’m looking for:
I don’t know what else to do…

Why is compileSdkVersion not being recognized even though it’s declared in mainTemplate.gradle ?

How can I resolve dependency conflicts (e.g., androidx.lifecycle)?
Is there a simple way to “force” Unity to use the correct Gradle configurations?
I’m out of ideas, and I would greatly appreciate any help or suggestions.

Thank you so much for your time and assistance! :pray:

Unity 2023.2 is no longer supported, could you check Unity 6 and see if that resolves your issue.

1 Like

I already did that, it didn’t change anything…

Could you attach Editor.log from Unity 6 where the failure occurs?

Thank you for your response. I’m sending you the document below.
editor_log.txt (1.5 MB)

From the error, it looks like a failure from dependency resolver which is maintained by Google.

I would suggest updating to latest resolver from here GitHub - googlesamples/unity-jar-resolver: Unity plugin which resolves Android & iOS dependencies and performs version management

specifically unity-jar-resolver/external-dependency-manager-1.2.183.unitypackage at master · googlesamples/unity-jar-resolver · GitHub and then resolving again.

Note: The dependencies should be injected in gradle files in the gradle templates. If the dependencies are downloaded directly to Unity project, then most likely it will continue to fail.