[android] Manually install Gradle and use it in Android Studio

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

The answer is


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

  1. Download gradle
  2. Extract the file to a specific location you desire
  3. Open android studio Click on setting and on build, execution and deployment, then gradle
  4. Enable work offline and change service directory to the location of the extracted filed.

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:

enter image description here

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:

  • I tried, it works, though this is not suggested for gradle use in general.
  • And, with this solution, each time open project, android-studio will ask to confirm whether to use gradlew instead, it's kinda annoying.

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:

  • Get the hash.
    • Start android-studio.
    • Create a basic project.
    • Then it will create the hash, and start to download gradle.
      e.g .gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/
    • Close android-studio.
    • Find the download process, by android-studio.
      e.g ps -aux grep | android
    • Kill all the related android processes.
    • Remove the blank project.
  • Download gradle by hand.
  • Start Android Studio and try again.
    • Create a new blank project again.
    • Then it shouldn't need to download gradle again.
    • It will uncompress gradle in the the same dir.
      e.g .gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/gradle-4.10.1/
    • And starts to sync dependencies, indexing, and build.

Tips:

  • After restart Android Studio & creating blank project again, if you see it says waiting for other process to download the distribution.
    That means you didn't kill the previous download process, kill it first, then remove blank project, then create a new project to confirm again.
  • Each version of 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

  • Since it's so slow when download gradle distrbution within Android Studio.
    It's better to provide an option to choose local 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.


If you are on LINUX follow the steps below:

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


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to gradle

Gradle - Move a folder from ABC to XYZ A failure occurred while executing com.android.build.gradle.internal.tasks Gradle: Could not determine java version from '11.0.2' Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 Failed to resolve: com.android.support:appcompat-v7:28.0 Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)

Examples related to android-studio

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK