如何在Android Studio的Gradle中获取JDK路径? [英] How to get the JDK path in Gradle within Android Studio?

查看:190
本文介绍了如何在Android Studio的Gradle中获取JDK路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要构建一些Android项目,必须设置环境变量 JAVA_HOME .(请参阅此Stack Exchange问​​题 flutter错误报告.)

In order to build some Android projects, it's necessary to set the environment variable JAVA_HOME. (See this Stack Exchange question and flutter bug report.)

我正在处理的项目就是这种情况.我想更改Gradle文件,因此不必设置 JAVA_HOME .

This is the case for a project I'm working on. I would like to change the Gradle file so it is not necessary to set JAVA_HOME.

Gradle是否有办法获取封闭的Android Studio进程使用的JDK的路径(或使该进程在无需用户干预的情况下通过JDK传递)?尚未设置code> JAVA_HOME .

Is there any way for Gradle to get the path to the JDK used by the enclosing Android Studio process (or for the process to pass in the JDK without user intervention)? This should work when JAVA_HOME had not been set.

推荐答案

您可以在 your_project_path/app/build.gradle

task javaHome {
    println "JAVA_HOME:" + System.getProperty("java.home")
}

运行任务:

./gradlew -q app:javaHome

结果:

JAVA_HOME:/usr/lib/jvm/java-8-openjdk-amd64/jre

这篇关于如何在Android Studio的Gradle中获取JDK路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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