在 Mac 上使用 Android Studio 中捆绑的 JDK 作为 JAVA_HOME [英] Using JDK that is bundled inside Android Studio as JAVA_HOME on Mac

查看:27
本文介绍了在 Mac 上使用 Android Studio 中捆绑的 JDK 作为 JAVA_HOME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试打开 Android 设备监视器,Studio 向我显示了此消息 =-O:

I tried to open Android Device Monitor and the Studio showed me this message =-O :

这让我很惊讶,因为如果我没有安装任何 Java,我怎么能够开发 Android 应用程序?!实际上,Android Studio 附带了捆绑的 JDK/JRE(位于 /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home),但系统找不到它:执行 <代码>usr/libexec/java_home 给出

It surprised me, because how have I been able to develop Android apps if I didn't have any Java installed?! Actually, Android Studio comes with bundled JDK/JRE (located in /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home), but it is not found by the system: executed usr/libexec/java_home gives

Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.

$JAVA_HOME 设置为 /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home 没有帮助 — source .bash_profile不喜欢它是一个目录.

Setting $JAVA_HOME to /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home did not help — source .bash_profile doesn't like that it's a directory.

问题:如果我已经在 Android Studio 中安装了新的 JDK,我不想安装新的 JDK.如何将其设置为系统默认值?

QUESTION: I don't want to install new JDK if I already have one inside Android Studio. How do I set it as system default?

推荐答案

将正确的字符串添加到 .bash_profile(并使用 source .bash_profile 重新加载):

Add the correct string to .bash_profile (and reload with source .bash_profile):

  1. Big Sur 之前的 MacOS 版本:export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/.
  2. Catalina、Big Sur、Mentere 及以上:export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/Contents/Home

如果您使用 Catalina 及以上版本,您很可能使用 zsh 作为 shell 而不是 bash.在这种情况下,请将其添加到您的主目录中的 .zshrc.zprofile 而不是 .bash_profile.

If you're using Catalina and above, you most probably use zsh as a shell instead of bash. In that case, add it to .zshrc or .zprofile instead of .bash_profile in your home directory.

之后不要忘记重新启动操作系统.

Don't forget to restart the operating system after.

之后,运行 java -version 给出了这个输出,Java 开始正常执行:

After that, running java -version gave this output and Java started to execute normally:

openjdk version "1.8.0_112-release"
OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
OpenJDK 64-Bit Server VM (build 25.112-b06, mixed mode)

至于 Android Device Monitor——它仍然需要这个古老的 JRE 版本 6.

As for the Android Device Monitor — it still demands this ancient JRE version 6.

这篇关于在 Mac 上使用 Android Studio 中捆绑的 JDK 作为 JAVA_HOME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆