Gradle Build Failed(Urgent pls)

I finally made a simple demo of my first game for android. But the editor said "Gradle Build Failed" when building an apk. I'm stumped by the followed response

FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':launcher'.

Could not resolve all artifacts for configuration ':launcher:classpath'.
Could not resolve com.android.tools.build:gradle:4.0.1.
Required by:
project :launcher
Could not resolve com.android.tools.build:gradle:4.0.1.
Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.0.1/gradle-4.0.1.pom'.
Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.0.1/gradle-4.0.1.pom'.
dl.google.com
Could not resolve com.android.tools.build:gradle:4.0.1.
Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/4.0.1/gradle-4.0.1.pom'.
Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/4.0.1/gradle-4.0.1.pom'.
jcenter.bintray.com
* 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 5s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

So how can I solve the problem and build the apk successfully? Word can't express how thankful I am if sombody could tell me the solution.

I've seen this Gradle error a lot lately... here's a post:

https://discussions.unity.com/t/706536

In general:

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.

https://discussions.unity.com/t/887277

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

https://discussions.unity.com/t/891017/7

Android Gradle errors and other related stuff:

https://discussions.unity.com/t/901712/2

[quote=“Kurt-Dekker”, post:2, topic: 916123]
I’ve seen this Gradle error a lot lately… here’s a post:

https://discussions.unity.com/t/706536

In general:

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.

https://discussions.unity.com/t/887277

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

https://discussions.unity.com/t/891017/7

Android Gradle errors and other related stuff:

https://discussions.unity.com/t/901712/2
[/quote]
Thanks very much! And I solved it by setting the correct environmental varible for SDK and JDK,including SDK tools.

1 Like