How to Setup gradle-2.2.1-all.zip Manually

2019-03-27 15:26发布

问题:

I want to run my unit test with this command

gradlew.bat connectedInstrumentTest

But it tries to download https://services.gradle.org/distributions/gradle-2.2.1-all.zip

And my corporal network blocks it. Hence, I want to setup the zip manually, I already downloaded it from browser.

The ways I failed are listed below

  • Pasting it in Program Files\Android\Android Studio\gradle\ gradle-2.2.1 didn't work
  • File -> Settings -> Build execution, Deployment -> Build Tools and defining the gradle home directory didn't work

Any suggestions except these will be much appreciated. Thanks.

回答1:

In your command you're using the Gradle Wrapper. The Gradle wrapper is a thin wrapper around the real Gradle bin. It's intended to be checked in to your source control and it then downloads the version of Gradle you've defined in gradle/wrapper/gradle-wrapper.properties. The advantage here is the version of Gradle used in the build is directly tied to the source control.

You have 2 options:

  • use the gradle command instead of gradlew - this will use the gradle that's installed on the local machine (assumes that 'gradle' is on the PATH). The drawback here is you have to have installed Gradle somewhere before the build will work.
  • change distributionUrl in gradle/wrapper/gradle-wrapper.properties to point to a different URL and host that file yourself somewhere. You get all the advantages of the wrapper but fix the problems you're having downloading it.


回答2:

Solution :

1). Delete the C:\Users\username\.gradle folder

2). Download http://downloads.gradle.org/distributions/gradle-2.2.1-all.zip

3). Create a new project in android studio.

4). When this time it stucks at gradle building, Force close the android studio.

5) Now go to C:\Users\username\.gradle\wrapper\dists\gradle-2.2.1-all\c64ydeuardnfqctvr1gm30w53 (the end directory name may be different)

6) Delete gradle-2.2.1-all.zip.lck and other files from this directory.

7) Paste the new downloaded gradle-2.2.1-all.zip here.

8) Run the android studio. :)