本文介绍了在OSX上运行./gradlew时,JAVA_HOME设置为无效目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从Android项目目录中运行./gradlew,但是出现以下错误:

I tried running ./gradlew from an Android project directory, but I get an error of:

请在您的环境中设置JAVA_HOME变量以使其与 您的Java安装位置.

Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

我尝试过的事情:

  1. 已导航到/Library/Java/JavaVirtualMachines. jdk1.8.0_11.jdk存在,但jdk1.7.0_79.jdk

which java打印出/usr/bin/java

printenv印刷品

JAVA_HOME =/库/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home JDK_HOME =/库/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home JDK_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home

...

  1. javac -version打印javac 1.8.0_11

which javac打印/usr/bin/javac

推荐答案

检查/usr/libexec/java_home是否存在.如果可以,请尝试运行

Check if /usr/libexec/java_home exists. If it does then try running

export JAVA_HOME=`/usr/libexec/java_home`

,然后重新运行gradlew构建.如果可以,请永久使用

and rerunning your gradlew build. If it works then make it permanent with

echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile

这篇关于在OSX上运行./gradlew时,JAVA_HOME设置为无效目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 06:23