Reputation: 679
I'm learning Android development from this YouTube playlist which stated that I need to install a JDK(Java Development Kit) separately for using Android Studio. But when I went through the tutorials, I was able run the apps without needing to install JDK separately.
Does this mean that it was necessary to install JDK(Java Development Kit) separately in older versions of Android Studio, but not in newer versions of it?
Upvotes: 59
Views: 129007
Reputation: 10400
I wanted to test Android Studio on OpenJDK13 instead of an embedded jre11. I did not want to create a global envvar STUDIO_JDK | JAVA_HOME
in a control panel. I made a small studio-start.bat
script to run Android Studio IDE on a custom Java JDK version.
Android Studio Bumblebee | 2021.1.1 Build #AI-211.7628.21.2111.8092744, built on January 19, 2022
has this embedded Java virtual machine.
c:\android-studio\jre\bin\java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
OpenJDK 64-Bit Server VM (build 11.0.11+9-b60-7590822, mixed mode)
I want to try run IDE on this Java.
C:\java\jdk-13.0.2\bin\java --version
openjdk 13.0.2 2020-01-14
OpenJDK Runtime Environment (build 13.0.2+8)
OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
Create C:\android-studio\studio-start.bat
script.
@REM Use custom JDK for AndroidStudio IDE
@set basedir=%~dp0
set STUDIO_JDK=C:\java\jdk-13.0.2
call "%basedir%bin\studio.bat
@rem the following commands did not use a custom JDK envvar.
@rem start "AndroidStudio" /I "%basedir%studio64.exe"
@rem "%basedir%studio64.exe"
Upvotes: 0
Reputation: 2843
Apparently not. I went through the steps to install flutter, including Android Studio.
However, flutter doctor
produced an issue:
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
I eventually found the path/to/sdkmanager, which was
/Users/<Mac User Name>/Library/Android/sdk/tools/bin/sdkmanager
but then running
/Users/<Mac User Name>/Library/Android/sdk/tools/bin/sdkmanager --install "cmdline-tools;latest"
produced the error:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Based on posts such as this page, I reluctantly started looking at installing Java. However, I found that Java is included in Android Studio, so I ran:
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/Contents/Home
but then
/Users/<Mac User Name>/Library/Android/sdk/tools/bin/sdkmanager --install "cmdline-tools;latest"
produced an exception:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
However, as indicated here: https://flutter-examples.com/flutter-command-line-tools-component-is-missing/ , the solution was to use Android Studio to install the Android sdk Command-line Tools (Latest).
Once I had done that, there was no longer a need to run --install "cmdline-tools;latest"
because the cmdline-tools;latest
had already been installed by Android Studio.
I was then able to run flutter doctor
and follow the instructions to get flutter doctor
to not identify any issues.
I would also note that Android Studio did not download the other sdk components until I actually created a project with Android Studio.
I was able to download an Android emulator and get the project to run on the emulator without installing Java except what came with Android Studio
Upvotes: 5
Reputation: 555
Just added JAVA_HOME=/path/to/jdk and STUDIO_JDK=/path/to/jdk in studio.sh and everything works
Upvotes: 1
Reputation: 536
You used to need to install a JDK; hence the videos telling you how to do it. Recent versions include a built-in JDK. Note that Android Studio has evolved rapidly, and tutorials quickly become obsolete.
Note that installing Android Studio doesn't automatically configure the built-in JDK command line tools. This matters if you want to use the Android SDK command line tools. To fix this, find the bin
directory within the Android Studio installation that contains the java
command (the native command that actually runs the Java Virtual Machine), and add it to your path. (Another thing that might change, so I won't add specific directories to this answer.) This file is java.exe
on Windows; on every other platform it's called java
and has executable permission.
(You'll also need to add the directories containing the SDK tools themselves.)
There are actually two such directories, because the JDK, like all Java applications, contains a Java Runtime Environment (JRE). If you just want to run the SDK tools, then it doesn't matter which bin
directory you choose. But if you want to compile and run Java code outside Android Studio, then you need to use the bin
containing the javac
command, among other essential JDK development tools.
Or you can just install the latest JDK. No real reason not to.
Upvotes: 10
Reputation: 471
On the Mac, the path for Android Studio's Java environment can be set with this export command:
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/
This uses the JAVA (OpenJDK) that comes with Android Studio.
Upvotes: 26
Reputation: 191681
Android Studio version 2.2 and higher comes with the latest OpenJDK embedded in order to have a low barrier to entry for beginners.
It is, however, recommended to have the JDK installed on your own as you are then able to update it independent of Android Studio.
If you are working with an Android API < 24, then you'll need to compile the project with Java 7 or do some extra steps to enable Java 8 features. (Note: Java 8 support is relatively new).
Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features
Upvotes: 63
Reputation: 891
This is what Google says on https://developer.android.com/studio/intro/studio-config.html:
A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version we recommend you use for your Android projects.
So if you are using the newest version, you won't need any additional JDK. Furthermore, the official installation instructions don't include anymore any hints towards the JDK, compared to June 2016.
Upvotes: 89