Manually install Gradle and use it in Android Studio

后端 未结 17 2103
忘掉有多难
忘掉有多难 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: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.

提交回复
热议问题