Manually install Gradle and use it in Android Studio

后端 未结 17 2030
忘掉有多难
忘掉有多难 2020-12-07 11:35

I\'m using Android Studio. How can I manually install and use Gradle within Android Studio.

I\'ve downloaded Gradle from http

相关标签:
17条回答
  • 2020-12-07 12:07

    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
    
    0 讨论(0)
  • 2020-12-07 12:09

    (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.
      • Go to the hash folder.
        e.g .gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/
      • There is a partly download file.
        e.g gradle-4.10.1-all.zip.part
      • Download the exact version by hand.
        from website: https://services.gradle.org/distributions/
        e.g https://services.gradle.org/distributions/gradle-4.10.1-all.zip
      • Remove the *.part file.
      • And copy the download file there instead.
        e.g .gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/gradle-4.10.1-all.zip
    • 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.
    0 讨论(0)
  • 2020-12-07 12:10

    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.

    0 讨论(0)
  • 2020-12-07 12:11

    download the desired pacakge Then modify the distribution line to

    distributionUrl=file:/c:/Gradle/gradle-5.5.1-all.zip
    
    0 讨论(0)
  • 2020-12-07 12:16

    Android Studio will automatically use the Gradle wrapper and pull the correct version of Gradle rather than use a locally installed version. If you wish to use a new version of Gradle, you can change the version used by studio. Beneath your Android Studio's project tree, open the file gradle/wrapper/gradle-wrapper.properties. Change this entry:

    distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip

    0 讨论(0)
  • 2020-12-07 12:17

    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\

    0 讨论(0)
提交回复
热议问题