Java 如何手动设置 gradle-2.2.1-all.zip

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31405947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 11:03:51  来源:igfitidea点击:

How to Setup gradle-2.2.1-all.zip Manually

javaandroidunit-testingandroid-studiogradle

提问by Egemen Hamut?u

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

但它试图下载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.

我的下士网络阻止了它。因此,我想手动设置 zip,我已经从浏览器下载了它。

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
  • 将其粘贴到 Program Files\Android\Android Studio\gradle\ gradle-2.2.1 中不起作用
  • 文件 -> 设置 -> 构建执行,部署 -> 构建工具和定义 gradle 主目录不起作用

Any suggestions except these will be much appreciated. Thanks.

除了这些之外的任何建议将不胜感激。谢谢。

采纳答案by andyberry88

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.

在您的命令中,您使用的是Gradle Wrapper。Gradle 包装器是围绕真正的 Gradle 箱的薄包装器。它旨在签入您的源代码管理,然后下载您在gradle/wrapper/gradle-wrapper.properties. 这里的优点是构建中使用的 Gradle 版本直接绑定到源代码管理。

You have 2 options:

您有 2 个选择:

  • use the gradlecommand instead of gradlew- this will use the gradlethat'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 distributionUrlin gradle/wrapper/gradle-wrapper.propertiesto 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.
  • 使用gradle命令而不是gradlew- 这将使用gradle安装在本地机器上的命令(假设 'gradle' 在 PATH 上)。这里的缺点是您必须在构建工作之前在某处安装 Gradle。
  • 改变distributionUrlgradle/wrapper/gradle-wrapper.properties为指向不同的URL和主机文件自己的地方。您可以获得包装器的所有优点,但可以解决下载时遇到的问题。

回答by Abhigyan

Solution :

解决方案 :

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

1)。删除 C:\Users\username\.gradle 文件夹

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

2)。下载http://downloads.gradle.org/distributions/gradle-2.2.1-all.zip

3). Create a new project in android studio.

3)。在 android studio 中创建一个新项目。

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

4)。当这一次它卡在 gradle 构建中时,强制关闭 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)

5)现在去C:\Users\username\.gradle\wrapper\dists\gradle-2.2.1-all\c64ydeuardnfqctvr1gm30w53(最终目录名可能不同)

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

6) 删除该目录下的gradle-2.2.1-all.zip.lck等文件。

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

7) 将新下载的 gradle-2.2.1-all.zip 粘贴到这里。

8) Run the android studio. :)

8) 运行安卓工作室。:)