Cordova isn’t working with Java 9. How to fix

Did anyone try runningcordova build on a computer with Java 9? Well, I tried and got this.
Requirements check failed for JDK 1.8 or greater

Apparently, Cordova is unable to identify Java 9 is greater than Java 8. More precisely Android is not supporting Java 9 yet. Here is the problem I’m describing.

If anyone is wondering what the heck is Cordova and what is the use of it, let me quote the Wikipedia.

Apache Cordova is a mobile application development framework originally created by Nitobi. Adobe Systems purchased Nitobi in 2011, rebranded it as PhoneGap, and later released an open source version of the software called Apache Cordova.Apache Cordova enables software programmers to build applications for mobile devices using CSS3, HTML5, and JavaScript instead of relying on platform-specific APIs like those in Android, iOS, or Windows Phone.

Look at the bolded text, let me rephrase. Cordova allows non-mobile application developers (like me) to develop mobile applications with technologies they already know (CSS3, HTML5, and JavaScript). Interested? I thought so, go and take a look at www.cordova.apache.org.

Anyway, I was working on a new product (More details for later). It consists of an API and mobile application. Since I never created a mobile application with native APIs before and I have only very little time period, I thought to give Cordova a try.

So what is the fix? I needed to run commandcordova build and build the app. Sadly there is no fix for Java 9 yet. Only workarounds. The most recommended way is to revert to Java 8 again. And that is exactly what I did. I reverted Path , Java_Home Environment Variables back to Java 8 and rancordova build without any issue.

I forgot to mention my Dev machine runs on Windows 10.

For Linux users, there is a bash script below. I found it from here.

The logic behind the script is running Cordova via Java 8 by setting,Path and JAVA_HOME variables explicitly. I did not test it so I can’t vouch for the success or failure of this script.

Do you have any workarounds or suggestions for “Cordova isn’t working with Java 9”? I love to hear. Please leave a comment below.

Photo by William Hook on Unsplash

Leave a Reply