简体   繁体   English

在 Android studio 中导入现有项目时如何设置 gradle home

[英]How to set gradle home while importing existing project in Android studio

How to set gradle home while importing existing project in Android studio.如何在 Android 工作室中导入现有项目时设置 gradle 主页。 While trying to import I need to set up this path.在尝试导入时,我需要设置此路径。在此处输入图像描述

The gradle plugin (which contains a bundled version of gradle) should be already installed in where/you/installed/android-studio /plugins/gradle so you shouldn't need to manually download it. gradle插件(包含捆绑版本的gradle)应该已经安装在/ you / installed / android-studio / plugins / gradle中,所以你不需要手动下载它。 Depending on the version of Android Studio, that last directory may be where/you/installed/android-studio /gradle/gradle-xyz (xyz is the version, so check your filesystem for the exact path). 根据Android Studio的版本,最后一个目录可能是/ you / installed / android-studio / gradle / gradle-xyz(xyz是版本,因此请检查文件系统中的确切路径)。

If you intend on doing gradle development outside Android Studio or want a different version, you can download it separately and point it at that path, but if you only want to get Android Studio working with the bundled version, this path should do it. 如果您打算在Android Studio之外进行gradle开发或想要一个不同的版本,可以单独下载并指向该路径,但如果您只想让Android Studio使用捆绑版本,则此路径应该执行此操作。

For Mac OS, you can use the following - 对于Mac OS,您可以使用以下 -

  1. /usr/local/opt/gradle/libexec/ or more generically - path/to/gradle/libexec/ - this is recommended. /usr/local/opt/gradle/libexec/或更一般 - path/to/gradle/libexec/ - 这是推荐的。 (the first path is what's achieved after installing gradle via Homebrew) (第一条路径是通过Homebrew安装gradle后实现的)
  2. /path/to/android/studio/plugins/gradle - I don't recommend this because this version of Gradle might be out of date, and Android Studio itself might say it's incompatible. /path/to/android/studio/plugins/gradle - 我不推荐这个,因为这个版本的Gradle可能已经过时了,Android Studio本身可能会说它不兼容。

You should be able to find it in C:\\Program Files\\Android\\Android Studio\\Gradle\\Gradle 2.2.1 . 您应该能够在C:\\Program Files\\Android\\Android Studio\\Gradle\\Gradle 2.2.1找到它。 This is running Windows 7 64-Bit. 这是运行Windows 7 64位。 Android Studio 1.0.2. Android Studio 1.0.2。

OSX (Less han two minutes) OSX(少两分钟)

  1. Open terminal 打开终端
  2. Check if Gradle installed gradle --version , if so, goto step 4 检查Gradle是否安装了gradle --version如果是,请转到步骤4
  3. If not brew install gradle and Goto step 2 如果不是brew install gradle 并转到步骤2
  4. Copy /usr/local/opt/gradle/libexec/ 复制/usr/local/opt/gradle/libexec/
  5. Paste it in Import Project Window in Android Studio > Gradle Home 将其粘贴到Android Studio> Gradle Home中的导入项目窗口中
  6. Important, Celebrate! 重要的是,庆祝!
  1. Download Gradle http://www.gradle.org/downloads 下载Gradle http://www.gradle.org/downloads
  2. Install 安装
  3. Set Gradle home to the install directory 将Gradle home设置为安装目录

On Linux run: whereis gradle . 在Linux上运行: whereis gradle

For me it was /usr/lib/gradle/1.10 . 对我来说是/usr/lib/gradle/1.10

I ran into same problem. 我遇到了同样的问题。 I selected location C:\\Program Files (x86)\\Android\\android-studio\\plugins\\gradle as Gradle Home 我选择了位置C:\\ Program Files(x86)\\ Android \\ android-studio \\ plugins \\ gradle作为Gradle Home

In Ubuntu 14.04 after $ sudo apt-get install gradle I've got $ sudo apt-get install gradle之后的Ubuntu 14.04中我得到了

$ whereis gradle
gradle: /usr/bin/gradle /usr/bin/X11/gradle /usr/share/gradle /usr/share/man/man1/gradle.1.gz

The path to Gradle was /usr/share/gradle Gradle的路径是/usr/share/gradle

对于Mac,

/Applications/Android Studio.app/Contents/gradle/gradle-3.2

Download Gradle as described above, but make sure you download version 1.9 and not the current release (1.11). 如上所述下载Gradle,但请确保下载1.9版而不是当前版本(1.11)。 I just had the same problem and downloaded the current release only to have Android Studio tell me it wasn't supported. 我只是遇到了同样的问题并且下载了当前版本,只是让Android Studio告诉我它不受支持。

On Arch Linux I could not find it, so I added: 在Arch Linux上我找不到它,所以我补充道:

echo $APP_HOME

to /usr/bin/grade (found over which gradle ) 到/ usr / bin / grade(找到which gradle

The Install dir for me was /usr/share/java/gradle/ 我的安装目录是/ usr / share / java / gradle /

For migrating from eclipse to android studio 用于从eclipse迁移到android studio

(Do not need to specify the Gradle home.) (不需要指定Gradle home。)

  1. Locate the project you exported from Eclipse, expand it, select the build.gradle file and click OK. 找到从Eclipse导出的项目,展开它, 选择build.gradle文件 ,然后单击OK。
  2. In the following dialog, leave Use gradle wrapper selected and click OK . 在以下对话框中, 选中Use gradle wrapper,然后单击OK

Try this for windows users 试试Windows用户

http://blog.blundell-apps.com/setting-up-android-studio-gradle-windows-7/ http://blog.blundell-apps.com/setting-up-android-studio-gradle-windows-7/

I tried byteit101's solution but whether I chose android-studio-path/plugins/gradle or android-studio-path/plugins/gradle/lib the IDE said it isn't correct. 我尝试了byteit101的解决方案,但无论我选择android-studio-path/plugins/gradle还是android-studio-path/plugins/gradle/lib ,IDE都说它不正确。

Then I changed the gradle home to android-studio-path/gradle/gradle-xxx and it works. 然后我将gradle home更改为android-studio-path/gradle/gradle-xxx并且它可以工作。

On Linux Mint 17 it was 在Linux Mint 17上它是

/usr/share/gradle

for me 为了我

Mac OSX / Linux Mac OSX / Linux

Step 1: Open terminal :)
Step 2: Open .bash_profile in vim to edit: 
        > vi ~/.bash_profile 
Step 3: Add line: 
        > export GRADLE_HOME=/usr/local/opt/gradle 
        (for me it was this location, it can be different for u)
Step 4: Add line: 
        > export PATH="$PATH:$GRADLE_HOME/bin" 
        (to export bin directory of gradle)
Step 5: Verify by reopening the terminal or new tab, and check by echoing: 
        > echo $GRADLE_HOME

If you are on a Windows machine, go to the directory: 如果您使用的是Windows计算机,请转到以下目录:

C:\Program Files\Android\Android Studio\gradle\

Click the gradle-4.4 folder from Android Studio\\File\\Settings , and then click the Apply button. 单击Android Studio \\ File \\ Settings中gradle-4.4文件夹,然后单击“ 应用”按钮。

在此输入图像描述

This is my solution on AndroidStudio/Idea for Mac 这是我在AndroidStudio / Idea for Mac上的解决方案

$ env | grep GRADLE
GRADLE_HOME=/usr/local/Cellar/gradle/2.6
GRADLE_USER_HOME=/Users/leon/.gradle

I used umake to install android studio. 我用umake来安装android studio。 For me the path was 对我来说,路径是

/home/user/.local/share/umake/android/android-studio/gradle/gradle-2.14.1

If you are on a Windows machine, gradle home is located inside the installation folder of your Android Studio, usually at: 如果您使用的是Windows计算机,则gradle home位于Android Studio的安装文件夹中,通常位于:

C:\Program Files\Android\Android Studio\gradle\gradle-5.1.1

Change the version if you have a different one. 如果您有不同版本,请更改版本。

Don't need to download or specify anything... 不需要下载或指定任何内容......

Just go to the install Android Studio plugins Path and search for any file like gradle-wrapper-x.xx.jar (x.xx = version number). 只需转到安装Android Studio插件路径并搜索任何文件,如gradle-wrapper-x.xx.jar(x.xx =版本号)。 Copy it to a subfolder of your project root folder named : gradle. 将其复制到名为:gradle的项目根文件夹的子文件夹中。

Example : - file found gradle-wrapper-1.12.jar in plugins folder of Android Studio Install's path - my project was on D:\\android_repo\\myProject - created a folder into D:\\android_repo\\myProject\\gradle - copy gradle-wrapper-1.12.jar to this folder D:\\android_repo\\myProject\\gradle - import again my project and no more question about gradle. 示例: - 文件在Android Studio Install的路径的plugins文件夹中找到了gradle-wrapper-1.12.jar - 我的项目在D:\\ android_repo \\ myProject上 - 在D:\\ android_repo \\ myProject \\ gradle中创建了一个文件夹 - copy gradle-wrapper- 1.12.jar到这个文件夹D:\\ android_repo \\ myProject \\ gradle - 再次导入我的项目,没有关于gradle的更多问题。

I am using Lubuntu, I ended up finding it in : 我正在使用Lubuntu,我最终找到了:

/usr/share/gradle 的/ usr /共享/ gradle这个

在Windows中

..\AndroidStudio2.0Beta6\android-studio\gradle\gradle-2.10

I've stumble across this question, trying to build an Ionic + Cordova app using Gradle from Android Studio installation, rather that installing Gradle separately. 我偶然发现了这个问题,尝试使用Android Studio安装中的Gradle构建Ionic + Cordova应用程序,而不是单独安装Gradle。

On Centos, the Gradle binary was here: /home/YOURUSERNAME/.gradle/wrapper/dists/gradle-VERSION-all/CUSTOM_HASH/gradle-VERSION/bin 在Centos上,Gradle二进制文件在这里: /home/YOURUSERNAME/.gradle/wrapper/dists/gradle-VERSION-all/CUSTOM_HASH/gradle-VERSION/bin

So, I've added export PATH=/home/maxim/.gradle/wrapper/dists/gradle-4.1-all/bzyivzo6n839fup2jbap0tjew/gradle-4.1/bin:$PATH to my ~/.bashrc and ionic cordova run android command worked just fine. 所以,我添加了export PATH=/home/maxim/.gradle/wrapper/dists/gradle-4.1-all/bzyivzo6n839fup2jbap0tjew/gradle-4.1/bin:$PATH到我的~/.bashrcionic cordova run android命令工作正好。

如果您使用的是Windows计算机,请转到目录C:\\ Program Files \\ Android \\ Android Studio \\ gradle \\并单击gradle文件夹并将其应用于

I had to use this 我不得不用这个

"C:\\Program Files\\Android\\Android Studio\\gradle\\gradle-4.1" “C:\\ Program Files \\ Android \\ Android Studio \\ gradle \\ gradle-4.1”

Change the version if you have a different one. 如果您有不同版本,请更改版本。

This worked. 这很有效。 C:\\Program Files\\Android\\Android Studio\\gradle\\gradle-3.2 C:\\ Program Files \\ Android \\ Android Studio \\ gradle \\ gradle-3.2

如果您正在使用MacPorts gradle的主页是:

/opt/local/share/java/gradle

For Ubuntu default version is /usr/lib/gradle/default . 对于Ubuntu,默认版本是/usr/lib/gradle/default In case of update, you don't need to reassign link in idea/studio. 如果更新,您无需在idea / studio中重新分配链接。

For OSX, if going to Finder, navigate to this category: /usr/local/opt/ if you do not see gradle folder, install your grandle version manually: 对于OSX,如果要访问Finder,请导航到以下类别: / usr / local / opt /如果您没有看到gradle文件夹,请手动安装您的grandle版本:

https://services.gradle.org/distributions/gradle-5.4.1-all.zip https://services.gradle.org/distributions/gradle-5.4.1-all.zip

https://services.gradle.org/distributions/gradle-4.4.1-all.zip https://services.gradle.org/distributions/gradle-4.4.1-all.zip

If you are looking for specific Gradle version, simply change the version number from the zip links above, unzip and add that in the Gradle folder /usr/local/opt/gradle 如果您正在寻找特定的Gradle版本,只需从上面的zip链接更改版本号,解压缩并将其添加到Gradle文件夹/ usr / local / opt / gradle中

On Windows it was在 Windows 它是

C:/Android Studio/jre C:/安卓工作室/jre

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将另一个Gradle项目导入现有android项目时拒绝了Android Studio访问 - Android Studio access denied while importing another gradle project into existing android project 将项目导入Android Studio时,如何使自动Gradle构建静音? - How to silence automatic gradle build while importing a project to Android Studio? 在android studio中导入项目时使用现有的gradle包装器 - using existing gradle wrapper while importing projects in android studio 如何将Gradle添加到Android Studio中的现有项目? - How to add Gradle to an existing project in Android Studio? 在Android Studio 0.5.2中导入项目时未显示gradle文件 - No gradle file shown while importing project in android studio 0.5.2 在Android Studio中导入Gradle Android项目时出错 - Error importing a Gradle Android project in Android Studio Android Studio 2.2坚持使用建筑Gradle项目信息导入现有项目 - Android Studio 2.2 Stuck at Building Gradle Project Info on importing existing project Android Studio:将项目导入现有项目 - Android Studio: Importing project into existing project 如何将现有的android项目(build.gradle)打开到android studio中 - How to open existing android project(build.gradle) into android studio 如何在导入项目时修复 Android Studio 4 上的 gradle 构建问题? - How to fix gradle build problems on Android Studio 4 while importing projects?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM