Workaround for issues where you are prompted to install the JDK when trying to build from the command line after installing Android Studio

Make a note of the part that was a little clogged when building the environment of Android Studio on mac.

problem

After installing Android Studio on my mac, when I tried to build with the following command outside Android Studio, the following error message and a dialog like a squeeze were displayed, and I was asked to install the JDK.

Build commands and error messages


$ ./gradlew assembleDebug
No Java runtime present, requesting install.

Dialog asking you to install the JDK スクリーンショット 2021-01-12 15.23.01.png

environment

solution

Android Studio already includes the JDK, so you can do it through the path.

The specific path can be found by selecting SDK Location in the left pane on the Android Studio menu> File> Project Structure screen and looking at the JDK Location. JDKパス確認画面.png

By the way, in the hint of this item, it was stated that "If you want to use it in an external process, add this path to JAVA_HOME ". JDKパスヒント.png

After writing the confirmed path in the ~/.zprofile file as follows, restart the terminal and the build command will be available.

.zprofile


export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"

reference

Recommended Posts

Workaround for issues where you are prompted to install the JDK when trying to build from the command line after installing Android Studio
Install lsb_release from the command line when lsb_release fails in docker environment
Introduction to Android App Development 1 Installing JDK and Android Studio for mac
What to do if build from command line fails in Android development environment
[Android studio / Java] What you don't understand when you touch it for the first time