I got an error building my unity project due to an error with the settings.gradle file.
See more details here:
FAILURE: Build failed with an exception.
* Where:
Settings file 'C:\Users\educp\Documents\Proyectos de unity\It's Complicated - copia\Library\Bee\Android\Prj\IL2CPP\Gradle\settings.gradle' line: 14
* What went wrong:
A problem occurred evaluating settings 'Gradle'.
> Could not find method dependencyResolutionManagement() for arguments [settings_9y2goy45mvwak9gvumvg94pgc$_run_closure1@4aecf086] on settings 'Gradle' of type org.gradle.initialization.DefaultSettings.
* 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 3s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
When I went to the settings.gradle file it displays this.
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
include ':launcher', ':unityLibrary'
include 'unityLibrary:GoogleMobileAdsPlugin.androidlib'
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
// Android Resolver Repos Start
def unityProjectPath = $/file:////$.replace("\\", "/")
maven {
url "https://maven.google.com/" // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7, Assets/GoogleMobileAds/Editor/GoogleUmpDependencies.xml:7
}
mavenLocal()
// Android Resolver Repos End
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
As it shows in the file it doesn't contain the argument Gradle but it seems it have a GoogleMobileAds library. Is this normal?? What is missing??
One more thing, there is an extended version of he problem here:
CommandInvokationFailure: Gradle build failed.
C:\Program Files\Unity\Hub\Editor\2021.2.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2021.2.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "bundleRelease"
stderr[
FAILURE: Build failed with an exception.
* Where:
Settings file 'C:\Users\educp\Documents\Proyectos de unity\It's Complicated - copia\Library\Bee\Android\Prj\IL2CPP\Gradle\settings.gradle' line: 14
* What went wrong:
A problem occurred evaluating settings 'Gradle'.
> Could not find method dependencyResolutionManagement() for arguments [settings_9y2goy45mvwak9gvumvg94pgc$_run_closure1@4aecf086] on settings 'Gradle' of type org.gradle.initialization.DefaultSettings.
* 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 3s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
]
stdout[
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <aa9f40e1a34f4b01ac44d2ce67124834>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <aa9f40e1a34f4b01ac44d2ce67124834>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <aa9f40e1a34f4b01ac44d2ce67124834>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <aa9f40e1a34f4b01ac44d2ce67124834>: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 <aa9f40e1a34f4b01ac44d2ce67124834>: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 <aa9f40e1a34f4b01ac44d2ce67124834>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <aa9f40e1a34f4b01ac44d2ce67124834>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <aa9f40e1a34f4b01ac44d2ce67124834>:0)
Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message, System.Exception ex) (at <aa9f40e1a34f4b01ac44d2ce67124834>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <aa9f40e1a34f4b01ac44d2ce67124834>:0)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, AndroidPlayerBuildProgram.Data.AndroidPlayerBuildProgramOutput buildProgramOutput) (at <aa9f40e1a34f4b01ac44d2ce67124834>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <aa9f40e1a34f4b01ac44d2ce67124834>:0)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.Int32 subtarget, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <52409df47eec4ff4a3e5a5be37682d54>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
One solution is to use Unity 2022.3 or higher. For older versions, you will need to do the following:
Assets/Plugins/Android
directory and delete gradleTemplate
, mainTemplate
and settingsTemplate
files. (Or move somewhere as backup).Edit -> Project Settings... -> Player
Android
tab and then open Publishing Settings
Custom Main Gradle Template
and Custom Gradele Properties Template
Assets -> External Dependency Manager -> Android Resolver -> Force Resolve
You most likely opened a project that was created in newer Unity version. Your Unity 2021.2.6f1 depends on a very old Gradle version that doesn't have dependencyResolutionManagement()
. By deleting gradle templates and generating them again, Unity will generate templates that are correct for the current version.
dependencyResolutionManagement
was added in Gradle 6.8 and your unity version uses Gradle 6.1.1 source