Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
Fix Gradle download failure (Android Studio)
When developing a project with Android Studio, gradle is typically used to manage dependencies. In China, however, gradle’s automatic download is often interrupted. Initially, I tried to get Android Studio to automatically download it, thinking that a few more attempts would fix the problem, but it didn’t work.
Later, I found that you can manually download the gradle version of the project from gradle’s official website and put it in the local directory to solve the problem.
Specific operation
-
Confirm the gradle version you want to download
Android Studio will download Gradle based on the version specified in {Projecdt}/gradle/wrapper/gradle-wrapper.properties.
gradle-wrapper.properties
#Sat Oct 16 16:58:20 CST 2021 distributionBase=GRADLE_USER_HOME distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip distributionPath = wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOMECopy the code
-
Go to gradle’s official website to download it
All Gradle releases are available for download at Gradle Review
In this example, gradle-wrapper.properties specifies gradle-6.7.1-bin.zip, so you need to download gradle-6.7.1-bin.zip from gradle’s official website.
Gradle must be downloaded according to gradle-wrapper.properties, otherwise it will not work.
-
Place the downloaded Gradle zip file in your local gradle directory.
Go to your local gradle directory and place the downloaded gradle file in it.
For Mac, gradle is in the user directory. By default, files are hidden, so you can’t see them. Command+Shift+. Toggles to show hidden directories and files. For Windows, Gradle is in the user directory.
Mac gradle directory example:
/Users/BS/.gradle/ Copy the code
Windows Gradle directory example:
C:\Users\BS\.gradle Copy the code
To open the wrapper/dists directory, you can find the directory to gradle version gradle-6.7.1-bin. After entering this directory, you will find a messy alphabetic and numeric directory that looks like a UUID. Just put the downloaded Gradle compressed files into this messy directory. There’s no need to unzip it, Android Studio does it automatically.
Mac gradle zip file location example (Windows similar, not listed) :
/ Users/BS /. Gradle/wrapper/dists/gradle 6.7.1 - bin/bwlcbys1h7rz3272sye1xwiv6Copy the code
And you’re done! Gradle dependency management can now be done happily with Android Studio.