在 MacOS 的命令行中使用 Android Studio 的内置 Java [英] Using Android Studio's built-in Java on the command line in MacOS

查看:18
本文介绍了在 MacOS 的命令行中使用 Android Studio 的内置 Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有很多关于在 Mac 上安装 Java 以及让 Android Studio 使用正确版本的信息(很多已经过时).但是最近的 Android Studio 版本(2.2 及更高版本?)提供了自己的 Java,对于大多数 Mac 用户来说,没有理由(或希望)再安装浏览器或命令行 Java 了......直到你想使用任何一个Studio 的shell 工具,发现都是java,而studio 的Java 并没有集成到java_home 的奇迹中.

There's lots of info here (much obsolete) on installing Java on the mac, and getting Android Studio to use the right versions. But recent builds of Android Studio (2.2 and on?) provide their own Java, and for most Mac users, there's just no reason (or desire) to install a browser or command line Java anymore ... until you want to use any of the Studio's shell tools, and realize they're all in java, and the studio's Java is not integrated into the wonder that is java_home.

显然,您的路径变量需要更新以包含 Android SDK,并且需要设置 JAVA_HOME 和 JDK_HOME,但这样做的实际细节并不多.

Obviously, your path vars need to be updated to include the Android SDK, and JAVA_HOME and JDK_HOME need to be set, but the actual details of doing so are thin on the ground.

那么……在 MacOS shell 中简单地使用 Studio 的嵌入式 java 和 android 工具而不是从 Oracle 安装额外的 Java 实例所需的正确路径和设置是什么?

So ... what are the correct paths and settings needed to simply use the Studio's embedded java and android tools in MacOS shells, instead of installing extra Java instances from Oracle?

推荐答案

将此添加到您的 ~/.profile 或类似内容:

Add this to your ~/.profile or similar:

# Use the JDK embedded with Android Studio 2020.3+ for command-line builds
export JAVA_HOME='/Applications/Android Studio.app/Contents/jre/Contents/Home'

# (Use the next line instead for older Android Studio 2.2+)
#export JAVA_HOME='/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home'

通过 gradlew 和任何其他行为良好的脚本进行命令行构建,然后将使用 Android Studio 2.2+ 附带的 SDK 版本.

Command-line builds via gradlew, and any other well-behaved script, will then use the version of the SDK that ships with Android Studio 2.2+.

这篇关于在 MacOS 的命令行中使用 Android Studio 的内置 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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