Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java JDK version to use given Oracle licensing changes #637

Closed
KevinKelchen opened this issue Jan 23, 2019 · 13 comments
Closed

Java JDK version to use given Oracle licensing changes #637

KevinKelchen opened this issue Jan 23, 2019 · 13 comments

Comments

@KevinKelchen
Copy link

Hi 👋 ,

I have a question regarding the version of the Java JDK we should be using in light of Oracle's recent Java licensing changes.

The official Cordova documentation for installing the JDK links to this downloads page on Oracle's site for Java JDK 8.

Somewhat recently Oracle announced that JDK 8 will not get new security updates after January 2019 if it's used for business/commercial purposes. This post tries to break down what the implications are. Other businesses are making adjustments to their applications because of the licensing changes.

Searching online it looks like Android Studio, for a while now, has shipped with OpenJDK...

Will the recommendation for Cordova Android change to an OpenJDK version of the JDK? Regardless of whether or not that recommendation changes, are OpenJDK versions supported in Cordova Android for those who do not wish to pay expensive licensing fees to Oracle in order to comply legally as well as to receive security updates with regard to the Cordova Android development they do for their business?

Thank you so much for your time! 😃

@janpio
Copy link
Member

janpio commented Jan 23, 2019

Good question @KevinKelchen!

Did you investigate a bit how Cordova could be used together with OpenJDK?
Does it work out of the box or does cordova-android have to change anything?

@KevinKelchen
Copy link
Author

Hi @janpio! I appreciate your responsiveness!

I have yet to actually experiment with using alternative JDK implementations for Cordova Android development. I thought I would ask here first to see if there was already official guidance because I thought that this topic may have already been discussed given its legal/financial implications. :-)

I'm not certain if a version of OpenJDK would work for Cordova Android or if there's an implicit dependency on the Oracle implementation. If an OpenJDK version will work, what distribution will work the best? I wonder if we could somehow use the OpenJDK that comes with Android Studio (if it's JDK 8) or if it would need to be installed separately or require a different distribution (perhaps desirable for decoupling Android Studio from being a Cordova Android requirement).

I may not get much time to investigate this for the next couple of months given higher priorities. However, if anyone else who comes across this thread has insight to share, please don't be afraid to comment!

@janpio
Copy link
Member

janpio commented Jan 23, 2019

(Just a note for anyone here reading this: My comment was made as an individual, not as a representation of all Apache Cordova maintainers and committers. I have no idea if people working more frequently with cordova-android might have thought about that before. I don't want to give a false impression here.)

@brodycj brodycj added the bug label Jan 23, 2019
@brodycj
Copy link

brodycj commented Jan 23, 2019

I would recommend using OpenJDK 8, which seems to be still updated with free support.

This means we need to update the download info in the following places:

I added the bug label, think this should be fixed before we make the major release for Cordova 9 (apache/cordova#10).

I posted the following answer on StackOverflow how to install and use OpenJDK 8 on mac, using Homebrew: https://apple.stackexchange.com/questions/349465/how-can-i-upgrade-from-oracle-jdk-8-to-openjdk-8-using-homebrew/349466#349466

As a side point, I think use with newer OpenJDK version is not supported by Android build tools: https://stackoverflow.com/questions/49788102/which-java-se-versions-work-with-android-studio-3-1

P.S. I tested build and run on Android with OpenJDK 8 with both latest and nightly Cordova-Android versions on my mac.

@KevinKelchen
Copy link
Author

Thank you so much, @brodybits! 😃

@sc0ttdav3y
Copy link

sc0ttdav3y commented Jul 23, 2019

Hi all,

Here's what worked for me as at July 2019, which is a TL;DR from all the links above along with some Google-fu. I can confirm this works on a clean MacOS Mojave, after first installing Android Studio 3.4.2 and Cordova 9.0.1.

Hope this helps someone.


Step one: Install OpenJDK 8 from brew.

brew tap AdoptOpenJDK/openjdk
brew cask install adoptopenjdk8

Step two: Update the environment variables to point to this version of the JDK (put the following into your ~/.bash_profile).

# The Android SDKs come from Android Studio and are placed here
export ANDROID_SDK_ROOT="$HOME/Library/Android/sdk"

# Point JAVA_HOME to your OpenJDK 8 
export JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home"

# Add the emulator to the path (so "cordova android run" works)
export PATH="${ANDROID_SDK_ROOT}/emulator:${PATH}"

Now close and re-open your terminal window.

Step three:

Now you should be able to run cordova build android 🎉


Notes:

  • I also had to accept the license agreement for the SDK before the build worked, and I couldn't immediately find that documented so here goes:
# Run this on your bash prompt
yes | $ANDROID_SDK_ROOT/tools/bin/sdkmanager "platforms;android-28"
  • The JAVA_HOME environment variable is only needed because Cordova's check_reqs.js currently doesn't handle searching for the required JDK (OpenJDK 8 = 1.8) when multiple JDKs are installed, which is the case when you install Android Studio (which installs JDK 12) and then install JDK 8 via brew. A fix for that may be to have the check_java() method in check_reqs.js (around line 145) run its /usr/libexec/java_home command with the parameter "-v 1.8", which will find 1.8's path (AdoptOpenJDK 8) when there are multiple JDKs installed.

I hope this helps someone.

@brodycj
Copy link

brodycj commented Jul 23, 2019

I think we should consider updating the following:

  • messages generated by cordova-android
  • README.md file in this repository
  • update likely needed on cordova-docs

I cannot promise when I will get a chance to work on these badly needed updates, just added the help wanted label.

P.S. Many thanks to @sc0ttdav3y and others for the helpful comments so far!

@breautek
Copy link
Contributor

Just wanted to pitch in that my primary work machine uses OpenJDK and I never once had a java related issue with cordova-android yet.

openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)

@PostImpatica
Copy link

@breautek ... ah, it's because I was using the latest version of OpenJDK which was 13. I just assumed the latest version would work but I guess I have to manually install the correct version.

@breautek
Copy link
Contributor

@breautek ... ah, it's because I was using the latest version of OpenJDK which was 13. I just assumed the latest version would work but I guess I have to manually install the correct version.

Yes, Java 8 is specifically a requirement from the android sdk 😄

Btw, Is there anything required to resolve this issue?

@breautek
Copy link
Contributor

breautek commented May 9, 2021

Closing due to inactivity. I believe the question has been answered.

@breautek breautek closed this as completed May 9, 2021
@jci-zimm
Copy link

Did something change recently with open JDK support? I thought I used it in the past. Now the verison check fails no matter what version of open JDK I use.

Requirements check failed for JDK 1.8.x! Detected version: 16.0.2

Where as when I run java version

java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (Zulu 8.46.0.19-CA-win32) (build 1.8.0_252-b14)
OpenJDK Client VM (Zulu 8.46.0.19-CA-win32) (build 25.252-b14, mixed mode)

Versus javac version

javac -version
javac 16.0.2

@breautek
Copy link
Contributor

You either don't have JDK 8 installed or you have JDK 16 appears before JDK 8 in your path.

Not sure about Zulu, but on ubuntu the package name is openjdk-8-jdk. You might only have openjdk-8-jre installed, which is just the java runtime environment, but not the development kit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants