Gradle error while building project on Unity v2020.3.40f1

Hey, I have been trying to get rid of the following error for days, but could found nothing. Would be very glad if someone could help me out. Here’s everything that console writes:
CommandInvokationFailure: Gradle build failed.
C:\Users\shakti\Documents\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath “C:\Users\shakti\Documents\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-6.1.1.jar” org.gradle.launcher.GradleMain “-Dorg.gradle.jvmargs=-Xmx4096m” “bundleDebug”
Environment Variables:
NVIDIAWHITELISTED = 0x01
USERDOMAIN = DESKTOP-RGCH6E0
ProgramFiles = C:\Program Files
TMP = C:\Users\shakti\AppData\Local\Temp
PROCESSOR_ARCHITECTURE = AMD64
PROCESSOR_REVISION = 6001
OS = Windows_NT
ALLUSERSPROFILE = C:\ProgramData
PROCESSOR_IDENTIFIER = AMD64 Family 23 Model 96 Stepping 1, AuthenticAMD
ProgramW6432 = C:\Program Files
USERPROFILE = C:\Users\shakti
JAVA_HOME = C:\Users\shakti\Documents\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK
CommonProgramFiles = C:\Program Files\Common Files
INTEL_DEV_REDIST = C:\Program Files (x86)\Common Files\Intel\Shared Libraries
ComSpec = C:\WINDOWS\system32\cmd.exe
MIC_LD_LIBRARY_PATH = C:\Program Files (x86)\Common Files\Intel\Shared Libraries\compiler\lib\mic
PSModulePath = C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PUBLIC = C:\Users\Public
USERNAME = shakti
NUMBER_OF_PROCESSORS = 12
JAVA_TOOL_OPTIONS = -Dfile.encoding=UTF-8
FPS_BROWSER_APP_PROFILE_STRING = Internet Explorer
HOMEDRIVE = C:
TEMP = C:\Users\shakti\AppData\Local\Temp
Path = C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\Java\jdk-19.0.2\bin;C:\Users\shakti\AppData\Local\GitHubDesktop\bin;C:\ProgramData\shakti\GitHubDesktop\bin;C:\Program Files\Git\cmd;C:\Program Files\Java\jre1.8.0_361\bin;C:\Windows\System32;C:\Users\shakti\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\shakti\AppData\Local\Programs\Python\Python310;C:\Users\shakti\AppData\Local\Microsoft\WindowsApps;C:\ProgramData\shakti\GitHubDesktop\bin;C:\Users\shakti\AppData\Local\GitHubDesktop\bin;C:\Users\shakti\Documents\2021.2.12f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools;C:\Users\shakti.dotnet\tools;C:\Users\shakti\AppData\Local\Programs\Microsoft VS Code\bin
COMPUTERNAME = DESKTOP-RGCH6E0
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
SystemDrive = C:
windir = C:\WINDOWS
FPS_BROWSER_USER_PROFILE_STRING = Default
HOMEPATH = \Users\shakti
CommonProgramFiles(x86) = C:\Program Files (x86)\Common Files
APPDATA = C:\Users\shakti\AppData\Roaming
OneDrive = C:\Users\shakti\OneDrive
DriverData = C:\Windows\System32\Drivers\DriverData
CommonProgramW6432 = C:\Program Files\Common Files
ProgramFiles(x86) = C:\Program Files (x86)
SystemRoot = C:\WINDOWS
SESSIONNAME = Console
LOGONSERVER = \DESKTOP-RGCH6E0
LOCALAPPDATA = C:\Users\shakti\AppData\Local
VBOX_HWVIRTEX_IGNORE_SVM_IN_USE = 1
PROCESSOR_LEVEL = 23
SHIM_MCCOMPAT = 0x810000001
USERDOMAIN_ROAMINGPROFILE = DESKTOP-RGCH6E0
ProgramData = C:\ProgramData
stderr[
FAILURE: Build failed with an exception.

  • Where:
    Build file ‘C:\Users\shakti\Documents\CricketGame\Temp\gradleOut\launcher\build.gradle’ line: 28
  • What went wrong:
    A problem occurred evaluating project ‘:launcher’.

No signature of method: java.lang.String.positive() is applicable for argument types: () values: [ ]
Possible solutions: notify(), tokenize(), size(), size()

  • 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 1s
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    ]
    stdout[
    ]
    exit code: 1
    UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0)
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0)
    UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0)
    UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action1[T] progress, System.String error) (at <e8d8d8782ef8400fa679b5177100ea99>:0) UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action1[T] progress) (at :0)
    Rethrow as GradleInvokationException: Gradle build failed
    UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at :0)
    UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :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 :0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0)
    UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at :0)
    UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at :0)
    UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, 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 <92e8e151ac2247a491cb6ca42a1bead9>:0)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

How to troubleshoot build failures:

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

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

Android Gradle errors and other related stuff: