[JAVA] Use the JDK used in Android Studio in the terminal

I'm a little addicted to it, so it's a post with notes.

Doesn't Java come in?

The other day, I got a new Mac, so I installed Android Studio and built a development environment. (Just install it.) The construction was completed, and I was able to execute the application without any problems by popping Android Studio, and I was proceeding with the development. So, when I tried to perform a Gradle task in the terminal,

No Java runtime present, requesting install.

And an error ...

I tried various things, "I was able to run it in Android Studio, but why do I get an error that Java is not included ...?"

Android Studio 2.2 and above bundles a copy of the latest version of OpenJDK

Yes, it was mentioned on the official website. https://developer.android.com/studio/intro/studio-config.html?hl=ja#jdk

You mean that you had a JDK in Android Studio and you were using it.

You can also check it from [File]> [Project Structure] in Android Studio. (↓ capture)

1af1ad7980757f92687112c914c8243e.png

What's more, it says recommended, so I knew that it was better to use the bundled OpenJDK.

Use the JDK used in Android Studio in the terminal

I understand why Java isn't available in the terminal. So, you can download it from the Oracle page, but I want to use it with the JDK bundled with Android Studio because it is a good idea. (On the contrary, it is better to unify it because it does not cause strange differences?)

Well, the method of passing the Java path is explained on many sites, so I will omit it, but it was OK with the following feeling.

.bash_profile


export PATH=$PATH:/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home/bin
export JAVA_HOME=/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home

You should now be able to perform Gradle tasks in your terminal without any issues: grinning:

Summary

Described how to use the JDK used in Android Studio in the terminal. I also found that it is recommended to use the bundled JDK.

Now that the environment is in place, we'll develop it: muscle:

Recommended Posts

Use the JDK used in Android Studio in the terminal
Use a JDK from another OpenJDK provider in Android Studio
How to use ExpandableListView in Android Studio
3 ways to import the library in Android Studio
Notes in Android studio
How to use UsageStatsManager in Android Studio (How to check the startup time of other apps)
Refer to C ++ in the Android Studio module (Java / kotlin)
Use the Findbugs plugin in Eclipse
Automatically insert `@SuppressWarnings` in Android Studio
OkHttp3 (GET, POST) in Android Studio
Expression used in the fizz_buzz problem
The problem that XML attributes are sorted arbitrarily in Android Studio
Specify the default JAVA_HOME used in buildship
I examined the file created when selecting Empty Activity in Android Studio
[Java] Use cryptography in the standard library
What wasn't fair use in the diversion of Java APIs on Android
Java to C and C to Java in Android Studio
Is it possible to put the library (aar) in the Android library (aar) and use it?
Impressions and doubts about using java for the first time in Android Studio
I stumbled on the Java version in Android Studio, so I will summarize it
Riot (chat app) development (settings) in Android Studio
Use JDBC Manager with the settings in jdbc.dicon.
Use custom images in Amazon SageMaker Studio notebooks
A story about the JDK in the Java 11 era
Android Studio development for the first time (for beginners)
[Java] Judgment by entering characters in the terminal
Get your version number in the Android app
Difficulties when implementing Alarm Manager in Android Studio
How to check Rails commands in the terminal
[Android Studio] I want to set restrictions on the values registered in EditText [Java]
A story that solved the problem that the Java (jdk) version was too high to use the h2o library in R and R Studio.
[Java] Let's declare variables used in the loop in the loop [Variables in the block]
I tried to organize the cases used in programming
I got a cannot resolve symbol in Android Studio
Source used to get the redirect source URL in Java
[Android Studio] [Java] How to fix the screen vertically
Asynchronous processing and Web API integration in Android Studio
Organized how to interact with the JDK in stages
[Android Studio] I want to use Maven library on Android
[Android] How to get the setting language of the terminal
Personal summary of the guys often used in JUnit 4
[Introduction] Display Android Studio Hello World on the emulator
[Swift] Use UserDefaults to save data in the app
[Android] Hook the tap of the anchor link in WebViewClient