Android Studio - OpenJDK 1.8 Vs Oracle JDK - android

Android studio used to complaint about using OpenJDK and was recommending Oracle JDK. However with latest Android Studio, that prompt has gone (probably due to the legal dispute between both the companies).
I today installed Oracle JDK 1.8.0.92 and Android Studio 2.1.1 seems to be running faster, a noticeably faster.
Any idea what's the current status of Android studio with respect to Java 1.8 and also with respect to OpenJDK vs Oracle JDK.
Thanks

There is one main advantage of openJDK, and that is you can add ALPN jar into bootclasspath which is currently not supported by OrcaleJDK.
ALPN is basically used for http2 protocol when communicating with an http2 enabled Server.
In android that can be used with a library like okhttp.

Related

Which JDK version is the latest supported by Android Studio?

I am trying to install Android Studio on Ubuntu 18.04.
I downloaded and extracted Android Studio 3.1, and was wondering which JDK version is the last supported by Android Studio.
According to Oracle JDK page, JDK 8 has reached EOL:
Oracle will not post further updates of Java SE 8 to its public download sites for commercial use after January 2019. Customers who need continued access to critical bug fixes and security fixes as well as general maintenance for Java SE 8 or previous versions can get long term support through Oracle Java SE Subscription or Oracle Java SE Desktop Subscription. For more information, and details on how to receive longer term support for Oracle JDK 8, please see the Oracle Java SE Support Roadmap.
I installed Oracle JDK 11.0.1 for my Android studio as it is latest, but it throws the error:
Error: Could not find or load main class com.intellij.idea.Main
Caused by: java.lang.ClassNotFoundException: com.intellij.idea.Main
When starting android studio.
java -version
Gives Output:
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
And
echo $JAVA_HOME
Gives Output
/usr/lib/jvm/jdk-11.0.1
Which JDK version should I use?
You should use the JDK version bundled with Android Studio; you don't need a separate JDK installation. The bundled JDK version is currently based on OpenJDK 8, but it's actively maintained by JetBrains, which backports security fixes and other improvements to that version.

How to configure Android studio to run on custom jdk which shipped with other jetbrain ides?

The reason I want to do this because when changing the jdk for Android Studio from 1.6 to 1.8 the font is unbearable to me it is too thin...
I have read it some where that because 1.6 use Apple Java with Quartz to render font and that's why 1.8 not rendering the same way as 1.6.
However, all other jetbrain ides like AppCode, Webstorm etc. are shipped with their own custom jdk 1.8 and the font look exactly the same as 1.6.
The reason I need to update this because seem like with the new build tools 24.0.0 I cannot use older jdk version to preview the layout file.
Is there a way to make Android Studio use same custom jdk with other jetbrains ides?
PS. I have try to copy the folder jre from AppCode and paste it in Android Studio but when I try to open it I see this error
'tools.jar' seems to be not in Studio classpath.Please ensure JAVA_HOME points to JDK rather than JRE
Although there are a lot of answer to that problem but I don't know this error is occur because doing it in a wrong way or not?
This is the java version that I used
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
Thanks.
Starting with Android Studio 2.2 Preview, Android Studio ships with the same JDK that the JetBrains IDEs ship with. You don't need to configure anything; just update to the new version.

is it true that Building with JDK8 makes the app not works on older Android OS versions?

I am using JDK8x64 (only) with Android Studio 2.1 and targeting Android 4+.
Here I think this JDK8x64 used for build system itself, not for exporting to Android. (So it is OK, because Java 8 is backward compatible). (OS: Win7x64)
But according to: https://forums.xamarin.com/discussion/48581/use-of-jdk-8-with-xamarin-android
Is it true that Building with JDK8 makes the app not works on older Android OS versions?
Any experience?
And what about JDK 8 with Xamarin Android?
You can use JDK 8 and the compiler will only use the features of Java that are available (you will not be able to use the latest features introduced in JDK 8 such as lambdas, otherwise you will get an error).
However, if you target Android N, you will be able to use OpenJDK 8's features, some of which are backward compatible with previous versions of Android (e.g. lambdas and method references are backwards compatible). To see what's available, check here:
Supported Java 8 Language Features and APIs
We been using v8 since it was released and have not had any problems within Xamarin.Android apps (or Java binding libraries):
>javac -version
javac 1.8.0_92
>java -version
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)
That said, Xamarin website does state:
OS-X Requirements
Xamarin.Android requires the following for use with Xamarin Studio on a Mac:
Java JDK 7 (1.7)
If you are developing solely for Android versions older than Android 5.0 Lollipop (API 21), Java JDK 6 (1.6) can still be used. Later versions of the JDK can also be installed to run alongside JDK 6 or JDK 7 if required by your machine.
Windows Requirements:
Xamarin.Android also requires that a 32-bit Java JDK 7 (1.7) be installed.
Later versions of the JDK can also be installed alongside JDK 7, if required by your machine.
To answer your question, yes this is true. But Android Studio tends to handle this for you, as stated by #tyczj. Lets say for example you are building an app from JDK8 for your Android 4+, but I want to run that same app on my Android 2.3, which I still have. It might not work due to compatibility issues. Although Android Studio takes care of this by allowing you to specify which version(s) you would like to support, it wouldn't hurt to look at differences between JDK8 and say, JDK6.

Compiling AOSP and running Android Studio on the same machine, a possible scenario?

I'm trying to get my Fedora 22 machine to be able to both compile AOSP, which requires OpenJDK 1.7, and run Android Studio, which requires OpenJDK 1.8 (for Gradle).
Is there a way to make them both work correctly and live happily together on the same OS?
You can have as many JDK versions (OpenJDK, Oracle, 6, 7, 8) installed as you want.
The make process for the AOSP project will probably pick up the version form the JAVA_HOME variable (perhaps you can even supply one yourself?).
In Android Studio you can select the JDK per module with right click on module -> open module settings -> SDK location.
I haven't tried it myself but I don't see any reason why this wouldn't work.

Is Sun Java really necessary for using Android SDK on Ubuntu 10.10? I prefer OpenJDK

I would prefer to just use openjdk-6-jdk (version 6b20-1.9.1-1ubuntu3). But I'm just starting the Android SDK installation, so if Sun (Oracle) Java is really needed, I suppose now is the time to install it. Any advice?
I'm using JDK for working on Android and it's fine :)
java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.1) (6b20-1.9.1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 17.0-b16, mixed mode)
And eclipse plugin too :)
I tried it and it is working. I built and ran my project without any errors. (If I encounter errors in the future, I'll know to try the Sun JDK.)
Thanks for the feedback.
BTW, I'm running Ubuntu 10.10, and
Eclipse Helios Service Release 1 Build id: 20100917-0705
My project targets Android 2.2.
It works so far.
But I'm just starting the Android SDK installation, so if sun java is really needed, I suppose now is the time to install it. Any advice?
The Dalvik cross-compiler expects Sun bytecode and will fail with OpenJDK-generated class files, by all reports. Also, I'm not sure if there are any issues with other tools, such as the Eclipse ADT plug-in. You are welcome to try it, though.
OpenJDK and the official Oracle compilers work using modern versions of the Android developer tools. Other Java compilers (e.g., GNU Classpath for Java) may or may not work.
For an "official" answer (by Andrew Hughes, who is "Free Java Software Engineer" at Red Hat, Inc):
We've never had any bug reports relating to this that I'm aware of.

Categories

Resources