手动安装 Gradle 并在 Android Studio 中使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26254526/
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
Manually install Gradle and use it in Android Studio
提问by Hymanuars
I'm using Android Studio. How can I manually install and use Gradle
within Android Studio
.
我正在使用 Android Studio。如何Gradle
在Android Studio
.
I've downloaded Gradle
from http://www.gradle.org/downloadsversion gradle-2.1-all.zip.
我已经Gradle
从http://www.gradle.org/downloads下载了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..
当我打开压缩文件时,我可以看到 bin、docs 等,但我不知道在哪里复制它。即使在复制了如何在 Android 中使用它之后..
采纳答案by Larry Schiefer
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:
Android Studio 将自动使用 Gradle 包装器并拉取正确版本的 Gradle,而不是使用本地安装的版本。如果您希望使用新版本的 Gradle,您可以更改 Studio 使用的版本。在 Android Studio 的项目树下,打开文件gradle/wrapper/gradle-wrapper.properties
. 更改此条目:
distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip
回答by Hackbal Teamz
https://services.gradle.org/distributions/
https://services.gradle.org/distributions/
Download The Latest Gradle Distribution File and Extract It, Then Copy all Files and Paste it Under:
下载最新的 Gradle 分发文件并解压,然后复制所有文件并将其粘贴到:
C:\Users\{USERNAME}\.gradle\wrapper\dists\
C:\Users\{USERNAME}\.gradle\wrapper\dists\
回答by guicey
Step 1: Go to the download site from Gradle: https://gradle.org/releases/
第 1 步:从 Gradle 转到下载站点:https: //gradle.org/releases/
Step 2: Extract the downloaded zip file into a directory.
第 2 步:将下载的 zip 文件解压缩到一个目录中。
Step 2: Hit Ctrl + Alt + S (mac: ? + ,) in Android studio/Intellij IDEA
第 2 步:在 Android Studio/Intellij IDEA 中按 Ctrl + Alt + S (mac: ? + ,)
Step 3: Goto: Build, Execution, Deployment >> Build Tools >> Gradle (Or just type in the searchbar Gradle)
第 3 步:转到:构建、执行、部署 >> 构建工具 >> Gradle(或只需在搜索栏中输入 Gradle)
Step 4: Select: (X) Use local gradle distribution and set Gradle home to your extracted Gradle directory. Click on apply.
第 4 步:选择:(X) 使用本地 gradle 发行版并将 Gradle home 设置为您提取的 Gradle 目录。点击申请。
Step 5: Get rid of your unnecessary gradle files delete:
- MyApp/gradle/
- gradlew
- gradlew.bat
第 5 步:摆脱不必要的 gradle 文件删除:
- MyApp/gradle/
- gradlew
- gradlew.bat
回答by Ajmal V Aliyar
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]
假设这是一个 windows 系统,我们使用的是gradle-2.1-all[适用于任何 gradle 版本,只需根据需要更改版本]
All the gradles can be found in http://services.gradle.org/distributions/
所有的 gradle 都可以在http://services.gradle.org/distributions/ 中找到
Check the <Your Project>\gradle\wrapper\gradle-wrapper.properties
Make sure the distributionUrlis
检查<Your Project>\gradle\wrapper\gradle-wrapper.properties
确保distributionUrl是
distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip
This is enough as it will automatically download the gradle.
这足够了,因为它会自动下载 gradle。
After doing the above stuff, if you have downloaded the zip, paste the gradle-2.1-all.zipin
C:\Users\<username>\.gradle\wrapper\dists\gradle-2.1-all\<some_hash_key>\
It will save the extra downloading time.
做好上面的东西后,如果您已经下载的zip,粘贴gradle-2.1-all.zip在
C:\Users\<username>\.gradle\wrapper\dists\gradle-2.1-all\<some_hash_key>\
它将节省额外的下载时间。
回答by MKY
1.Download the Gradle form gradle distribution
1.下载Gradle形式的gradle发行版
2.Extract file to some location
2.将文件解压到某个位置
3.Open Android Studio: File > Settings > Gradle > Use local gradle distributionnavigate the path where you have extracted the gradle.
3.Open Android Studio: File > Settings > Gradle > Use local gradle distribution导航到你解压gradle的路径。
4.click apply and ok
4.单击应用并确定
Done
完毕
回答by Okas
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.
在任何你喜欢的地方打开它。在 Android Studio 中,设置下是 Gradle 类别,如果需要,您可以在其中指定外部 gradle 位置。将 gradle bin 文件夹放入您的路径可能是有意义的。
回答by Gunaseelan
I used like this,
我是这样用的
distributionUrl=file\:///E\:/Android/Gradle/gradle-5.4.1-all.zip
And its worked for me.
它对我有用。
回答by Masih Mol.
Step 1. Download the latest Gradle distribution
步骤 1. 下载最新的 Gradle 发行版
Step 2. Unpack the distribution
步骤 2. 解压发行版
Microsoft Windows users
微软视窗用户
Create a new directory C:\Gradle with File Explorer.
使用文件资源管理器创建一个新目录 C:\Gradle。
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.
打开第二个文件资源管理器窗口并转到下载 Gradle 发行版的目录。双击 ZIP 存档以显示内容。将内容文件夹 gradle-4.1 拖到新创建的 C:\Gradle 文件夹中。
Alternatively you can unpack the Gradle distribution ZIP into C:\Gradle using an archiver tool of your choice.
或者,您可以使用您选择的存档工具将 Gradle 发行版 ZIP 解压缩到 C:\Gradle 中。
Step 3. Configure your system environment
步骤 3. 配置您的系统环境
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.
在系统变量下选择路径,然后单击编辑。为 C:\Gradle\gradle-4.1\bin 添加一个条目。单击确定保存。
Step 4. Verify your installation
步骤 4. 验证您的安装
回答by not2qubit
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 thissimple.
我不知道为什么有这么多关于这样做的扭曲描述。也许是因为 Android Studio (AS) 在不断变化/发展?然而,程序就是这么简单。
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.
假设您已经在合适的目录中安装了 Gradle,意味着您可能还为 定义了一个环境变量GRADLE_HOME
,如果现在没有定义它,并重新启动 AS。
For my example: GRADLE_HOME=C:\Gradle\gradle-5.2.1
对于我的例子: GRADLE_HOME=C:\Gradle\gradle-5.2.1
Then fire up AS and navigate to:
File > Settings > Build, Execution, Deployment > Gradle
然后启动 AS 并导航到:
文件 > 设置 > 构建、执行、部署 > 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:
现在,您需要做的就是选择:(o) Use local gradle distribution
。然后 AS 会告诉您它找到了您的本地 Gradle 路径:
Hit Apply
and Ok
and restart AS.
命中Apply
与Ok
并重新启动AS。
Now all the Gradle data can be found in your HOMEdirectory, usually located here (in this case on Windows):
现在所有的 Gradle 数据都可以在你的HOME目录中找到,通常位于这里(在这种情况下在 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
在最新的 AS 3.3.2 上测试
回答by Ezekiel Adewale
Follow these steps
按着这些次序
- Download gradle
- Extract the file to a specific location you desire
- Open android studio Click on setting and on build, execution and deployment, then gradle
- Enable work offline and change service directory to the location of the extracted filed.
- 下载gradle
- 将文件解压缩到您想要的特定位置
- 打开android studio 点击设置和构建、执行和部署,然后gradle
- 启用脱机工作并将服务目录更改为提取文件的位置。
This is what worked for me. I hope it helps.
这对我有用。我希望它有帮助。