I'm using Android Studio. How can I manually install and use Gradle
within Android Studio
.
I've downloaded Gradle
from http://www.gradle.org/downloads version gradle-2.1-all.zip.
When I open the zipped file I can see bin, docs etc, but I don't know where to copy it. And even after copying how to use it within Android..
This question is related to
android
gradle
android-studio
Step 1. Download the latest Gradle distribution
Step 2. Unpack the distribution
Microsoft Windows users
Create a new directory C:\Gradle with File Explorer.
Open a second File Explorer window and go to the directory where the Gradle distribution was downloaded. Double-click the ZIP archive to expose the content. Drag the content folder gradle-4.1 to your newly created C:\Gradle folder.
Alternatively you can unpack the Gradle distribution ZIP into C:\Gradle using an archiver tool of your choice.
Step 3. Configure your system environment
Microsoft Windows users
In File Explorer right-click on the This PC (or Computer) icon, then click Properties -> Advanced System Settings -> Environmental Variables.
Under System Variables select Path, then click Edit. Add an entry for C:\Gradle\gradle-4.1\bin. Click OK to save.
Step 4. Verify your installation
Assume, you have installed the latest gradle once. But, If your particular project gradle version not match with the gradle version that already installed in the machine, the gradle sycn want to download that version. To prevent this download there is one trick. First You have to know the gradle version that already installed in your machine. Go to : C:\Users{username}.gradle\wrapper\dists, here you see the versions allready installed, remember the latest version, assume it is gradle-6.1.1-all.zip . Now, come back to Android Studio. In your Opened project, navigate Android Studio's project tree, open the file gradle/wrapper/gradle-wrapper.properties. Change this entry:
distributionUrl=http\://services.gradle.org/distributions/gradle-6.1.1-all.zip
This way we prevent downloading the gradle again and again. But avoid this thing, if the version really old. If that, you will find this warning :
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.1.1/userguide/command_line_interface.html#sec:command_line_warnings
Follow these steps
This is what worked for me. I hope it helps.
1.Download the Gradle form gradle distribution
2.Extract file to some location
3.Open Android Studio : File > Settings > Gradle > Use local gradle distribution navigate the path where you have extracted the gradle.
4.click apply and ok
Done
download the desired pacakge Then modify the distribution line to
distributionUrl=file:/c:/Gradle/gradle-5.5.1-all.zip
I'm not sure why there are so many contorted descriptions of doing this. Perhaps because Android Studio (AS) is constantly changing/evolving? Nevertheless, the procedure is this simple.
Assuming you have already installed Gradle in a suitable directory, mean that you probably also defined an environment variable for GRADLE_HOME
, if not define it now, and restart AS.
For my example: GRADLE_HOME=C:\Gradle\gradle-5.2.1
Then fire up AS and navigate to:
File > Settings > Build, Execution, Deployment > Gradle
Now, all you need to do is to select: (o) Use local gradle distribution
.
AS will then tell you it found your local Gradle paths:
Hit Apply
and Ok
and restart AS.
Now all the Gradle data can be found in your HOME directory, usually located here (in this case on Windows):
# tree -L 2 $USERPROFILE/.gradle/ | tail -n +2
+-- build-scan-data
¦ +-- 2.1
¦ +-- 2.2.1
+-- caches
¦ +-- 3.5
¦ +-- 5.2.1
¦ +-- jars-3
¦ +-- journal-1
¦ +-- modules-2
¦ +-- transforms-1
¦ +-- transforms-2
¦ +-- user-id.txt
¦ +-- user-id.txt.lock
+-- daemon
¦ +-- 3.5
¦ +-- 5.2.1
+-- native
¦ +-- 25
¦ +-- 28
¦ +-- jansi
+-- notifications
¦ +-- 5.2.1
+-- workers
+-- wrapper
+-- dists
Tested on latest AS 3.3.2
Like @ said
https://services.gradle.org/distributions/
Download The Latest Gradle Distribution File and Extract It, Then Copy all Files and Paste it Under:
C:\Users\{USERNAME}\.gradle\wrapper\dists\
but you have to first make Android Studio try downloading the zip file and cancel it.
That way you can get the hash and copy the file and put it under the hash
https://services.gradle.org/distributions/
Download The Latest Gradle Distribution File and Extract It, Then Copy all Files and Paste it Under:
C:\Users\{USERNAME}\.gradle\wrapper\dists\
(There are 2 solutions mentioned in existing answers that might work, but the preferred one - manually download gradle for gradlew
, is lack of essential details, and cause it fail. So, I would add a summary with missing details to save the unnecessary time wasted, in case others encounter into the same issue.)
There are 2 possible solutions:
Solution A: Use location gradle
, and delete gradlew
related files. (not recommend)
Refer to this answer from this post: https://stackoverflow.com/a/29198101/
Tips:
Solution B: Download gradle
distribution manually for gradlew
. (recommended)
Android Studio will download gradle to sub dir named by a hash.
To download manually, need to download to the exact sub dir named by the hash.
Steps:
.gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/
ps -aux grep | android
.gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/
gradle-4.10.1-all.zip.part
*.part
file..gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/gradle-4.10.1-all.zip
Android Studio
and try again.
.gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/gradle-4.10.1/
Tips:
Android Studio
& creating blank project again, if you see it says waiting for other process to download the distribution.Android Studio
might use different gradle
version, thus might need to repeat this process once, when Android Studio
is upgraded.BTW:
Here is the dir layout on my Linux
(For Android Studio 3.3.1
, which use gradle
4.10.1)
eric@eric-pc:~/.gradle/wrapper
$ tree -L 4
. +-- dists +-- gradle-4.10.1-all +-- 455itskqi2qtf0v2sja68alqd +-- gradle-4.10.1 +-- gradle-4.10.1-all.zip +-- gradle-4.10.1-all.zip.lck +-- gradle-4.10.1-all.zip.ok
Suggestions to Android-Studio
Android Studio
.gradle
installation dir or .zip file to be used by gradlew
.1.Install gardle as per the given link http://services.gradle.org/distributions/ 2.Extract this downloaded file in C:\Gradle\gradle-4.5 location 3.set the environment of gradle This PC\properties\advance system settings\Environment variable 4.let's start Android studio And set the path of gradle C:\Gradle\gradle In Android studio
Unpack it where ever you like. In Android Studio under Settings is category Gradle where you can specify external gradle location if you want. It probably makes sense to put gradle bin folder into your path.
Step 1: Go to the download site from Gradle: https://gradle.org/releases/
Step 2: Extract the downloaded zip file into a directory.
Step 2: Hit Ctrl + Alt + S (mac: ? + ,) in Android studio/Intellij IDEA
Step 3: Goto: Build, Execution, Deployment >> Build Tools >> Gradle (Or just type in the searchbar Gradle)
Step 4: Select: (X) Use local gradle distribution and set Gradle home to your extracted Gradle directory. Click on apply.
Step 5: Get rid of your unnecessary gradle files delete:
- MyApp/gradle/
- gradlew
- gradlew.bat
in first step you should go to http://www.gradle.org/downloads and then choose your Gradle version and follow download link in GitHub and then download Gradle from GitHub. after your download is completed, you should extract the downloaded file in a directory (every directory that you want). finally open extracted folder and just run gradlew.bat and wait several minutes for completing download. and after completing download files, Gradle install itself automaticly. Gradle will work correctly for next times. i resolve this problem with this way and i tested it and every things are ok, so every one can test this way, it should working well. Good Luck.
Go to the download https://gradle.org/ and download the latest zip file (currently 3.1 is the latest version)
Extract the downloaded zip file into /opt/android-studio/gradle/.
Open your project in Android Studio and hit Ctrl + Alt + S
Search for Gradle in the Search bar of the setting window
Select: (X) Use local gradle distribution and set Gradle home to /opt/andriod-studio/gradle/gradle.x.x (where x.x is the vesrion of the gradle zip file you just downloaded.). Then click on apply.
Try to sync Gradle again if the sync has already failed.If not close your project and reopen your project.
Hope this solves your problem.
I used like this,
distributionUrl=file\:///E\:/Android/Gradle/gradle-5.4.1-all.zip
And its worked for me.
Assuming this is a windows system and we are using gradle-2.1-all [Applicable to any gradle version, just change the version as we need]
All the gradles can be found in http://services.gradle.org/distributions/
Check the <Your Project>\gradle\wrapper\gradle-wrapper.properties
Make sure the distributionUrl is
distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip
This is enough as it will automatically download the gradle.
After doing the above stuff, if you have downloaded the zip, paste the gradle-2.1-all.zip in
C:\Users\<username>\.gradle\wrapper\dists\gradle-2.1-all\<some_hash_key>\
It will save the extra downloading time.
Source: Stackoverflow.com