1

Android Studio keeps recommending me using Oracle JDK although I am using it already. I have installed Oracle JDK, configured all the "alternatives" and environment variables to make it default, but the warning is still there. Why is that? Should I configure this somewhere else? I know I can just click "Don't show again" but I'd like to know the reason and make sure I am using the Oracle JDK actually, is there a way to check it from inside Android Studio?

Android Studio OpenJDK warning appearing even when using Oracle JDK

Ivan
  • 63,011
  • 101
  • 250
  • 382
  • The terminal shows only that you're using Oracle's Java 8 **JRE**. You're most likely using OpenJDK for JDK. What does `javac -version` say? – Kayaman Sep 04 '16 at 18:14
  • @Kayaman `javac -version` says `javac 1.8.0_102`. Also `update-alternatives --config javac` shows the Oracle one has been chosen. – Ivan Sep 04 '16 at 18:17
  • Uninstall OpenJDK. After that you'll know for sure if Android Studio is pointing at it. Having multiple JDKs installed [can cause confusion](http://stackoverflow.com/questions/39304336/problems-fixing-java-lang-unsupportedclassversionerror-unsupported-major-minor). – Kayaman Sep 04 '16 at 18:20
  • @Kayaman Yeah, a guillotine is the best tool to get rid of the headaches... – Ivan Sep 04 '16 at 18:24
  • There's incredibly few valid use cases for having multiple JDKs installed. Especially when you don't know what uses which one. Besides, if you really miss your precious OpenJDK, you can reinstall it after you've solved the problem (something you can't do with a guillotine). – Kayaman Sep 04 '16 at 18:25
  • @Kayaman Sure, I don't know any but one: all the Java-dependent packages in the Ubuntu/Debian repositories require the OpenJDK packages to be installed. This is an artificial kind of problem, everything would work fine with Oracle's JDK actually, but the reality is the package dependencies are easier to satisfy than to bypass. – Ivan Sep 04 '16 at 18:31
  • Really. I've never had any problems with my home and work Oracle-only Ubuntu systems. Anyhow, it's theoretically possible that Android Studio is hallucinating about OpenJDK, but it's quite unlikely. There's some setting you've overlooked. – Kayaman Sep 04 '16 at 18:36
  • By the way. There is another legitimate reason for an average developer (that doesn't need any special features of a particular JVM) to have multiple JDKs installed: to test their apps making sure they run Ok on both so end-users won't face this problem and will be able to just use whatever is easier to get on their OS. – Ivan Sep 05 '16 at 09:32
  • That's not true. You need only the `JRE` to test whether it runs, not the full `JDK`. Even if there's a valid reason for testing my code with dozens of different JDKs, maybe I want to make sure it compiles properly on 1.6/1.7/1.8 and Oracle, OpenJDK and IBM. Do I install them on the same computer? Of course not. I'll have a set of acceptance tests that run docker containers with a single JDK installed on each. – Kayaman Sep 05 '16 at 10:20
  • @Kayaman Perhaps (if not say definitely) you are right but I prefer to follow the Occam's Razor principle and avoid introducing additional entities unless necessary so I could never even recognize a reason for a thing like a JRE to exist separately when there are full JDKs that include them, needless to say I prefer to just run a JAR with a different JVM without any special preparations like setting up Docker. That's subjective, of course but I believe this point of view has its right to exist and that there are people who share it. – Ivan Sep 05 '16 at 11:06

1 Answers1

1

I have found the reason myself - it is in how the Unity launcher panel works.

I have unpacked Android Studio to /opt/google/android-studio and ran it with /opt/google/android-studio/bin/studio.sh initially. After that I have right-clicked its icon appeared on the Unity panel and chosen to "lock it to launcher" for the icon to remain there. Ever after I have been starting Android Studio by pressing this icon.

What has been done behind the scenes is the reason for the problem. The system has created a shortcut file at ~/.local/share/applications/jetbrains-studio.desktop with the following content:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=Android Studio Setup Wizard
Icon=jetbrains-studio.png
Exec=/usr/lib/jvm/default-java/bin/java -Xbootclasspath/a:/opt/google/android-studio/bin/../lib/boot.jar -classpath /opt/google/android-studio/bin/../lib/bootstrap.jar:/opt/google/android-studio/bin/../lib/extensions.jar:/opt/google/android-studio/bin/../lib/util.jar:/opt/google/android-studio/bin/../lib/jdom.jar:/opt/google/android-studio/bin/../lib/log4j.jar:/opt/google/android-studio/bin/../lib/trove4j.jar:/opt/google/android-studio/bin/../lib/jna.jar:/usr/lib/jvm/default-java/lib/tools.jar -Xms256m -Xmx1280m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=240m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -da -Djna.nosys=true -Djna.boot.library.path= -Djna.debug_load=true -Djna.debug_load.jna=true -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -XX:+HeapDumpOnOutOfMemoryError -Dawt.useSystemAAFontSettings=lcd -Djb.vmOptionsFile=/opt/google/android-studio/bin/studio64.vmoptions -XX:ErrorFile=/home/administrator/java_error_in_STUDIO_%p.log -Djb.restart.code=88 -Didea.paths.selector=AndroidStudio2.1 -Didea.platform.prefix=AndroidStudio com.intellij.idea.Main
StartupNotify=false
StartupWMClass=jetbrains-studio
OnlyShowIn=Unity;
X-UnityGenerated=true

As the Exec= line says it runs the Studio JAR with what it considers the "default Java" (which does NOT seem to correspond what I have chosen with update-alternatives --config java) rather than with the manually installed Orecle JDK and does not involve the studio.sh script (that would pick Oracle JDK) at all.

Perhaps the reason for the wrong JDK choice is that the shortcut has been created before I have installed Oracle JDK. Now, as I have removed OpenJDK and the shortcut file and re-created it the same way, it says Exec=/usr/lib/jvm/java-8-oracle-amd64/bin/java... instead.

Ivan
  • 63,011
  • 101
  • 250
  • 382