[JAVA] Reinstall JDK for Cordova

It will be a little longer, but please keep in touch.

Background

Using Electron and Cordova, I want to develop a multi-platform application with HTML / CSS / JavaScript, and I am building an environment. I was able to create a test app for Windows, macOS, and iOS, but I stumbled upon the stage of preparing for Android.

The problem that occurred

It seems that the JDK version is old

After creating a test app with Cordova, I was able to test the actual iOS device. Checking the operation with the Android emulator → I want to test the actual machine, and when I try cordova run android after adding the platform with Cordova, it does not work well due to an error.

Error message


CordovaError: Requirements check failed for JDK 1.8 or greater

It seems that the version of JDK (Java Development Kit) in the current environment is old.

environment

Investigation

Check the JDK version.

First, check the JDK version by referring to the following site.

Uninstalling "Java 6 [Apple version]" http://www.keyton-co.jp/blog/article/Java6forMacUninstall

How to install / update the macOS JDK https://qiita.com/takayamag/items/1469c59370df348240f8

In the terminal do the following:

python


$ java -version

result


java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

It is the latest version.

Then do the following:

python


$ /usr/libexec/java_home -V

result


Matching Java Virtual Machines (4):
    10.0.1, x86_64:     "Java SE 10.0.1"        /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
    1.8.0_172, x86_64:  "Java SE 8"     /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home
    1.6.0_65-b14-468, x86_64:   "Java SE 6"     /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-468, i386:     "Java SE 6"     /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

There are multiple JVMs. You probably need JDK version control. There are some good articles about JDK version control:

[2018 version] 4 things to build Android development environment on mac

It's annoying ... (´ ・ ω ・ `) Instead, it seems to be quite difficult.

Premise

The machine is different from the one in the article "gulp crash on Node 10.0.0" that I uploaded the other day. Although it is an iMac for CG, video production, and design production, this machine is also undergoing trial and error to share the environment. I had Java 6 installed to use the Adobe CS6 apps.

Solution

As mentioned above, there are multiple JVMs, so it seems difficult to manage. We will be able to manage it one by one, but once we uninstall all Java, it will serve its original purpose.

Java removal

Uninstall Java 6 [Apple version]

Please uninstall referring to the above site.

Remove Java package information


$ sudo pkgutil --forget com.apple.pkg.JavaForMacOSX107

ruby:1.6.0.Remove jdk


$ sudo rm -rf  /Library/Java/JavaVirtualMachines/1.6.0.jdk/

Confirm deletion


$ ls -ld /Library/Java/JavaVirtualMachines/1.6.0.jdk

If ls: /Library/Java/JavaVirtualMachines/1.6.0.jdk: No such file or directory is returned, the deletion is successful.

Further confirmation


$ /usr/libexec/java_home -V

result


Matching Java Virtual Machines (2):
    10.0.1, x86_64:     "Java SE 10.0.1"        /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
    1.8.0_172, x86_64:  "Java SE 8"     /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

Uninstall Java 8

python


$ sudo rm -rf  /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/

Check the result


$ ls -ld /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/

If ls: /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/: No such file or directory is returned, the deletion is successful.

Further confirmation


$ /usr/libexec/java_home -V

result


Matching Java Virtual Machines (1):
    10.0.1, x86_64:     "Java SE 10.0.1"        /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

Uninstall Java 10

python


$ sudo rm -rf  /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/

Check the result


$ ls -ld /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/

If ls: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/: No such file or directory is returned, the deletion is successful.

Further confirmation


$ /usr/libexec/java_home -V

result


Unable to find any JVMs matching version "(null)".
Matching Java Virtual Machines (0):

Default Java Virtual Machines (0):

No Java runtime present, try --request to install.

Supplement

Execute each of the following to delete the package information related to the browser and environment settings.

python


$ sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin 
$ sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane 
$ sudo rm -fr ~/Library/Application\ Support/Java

result

When I ran cordova run android,

python


CordovaError: Failed to find 'JAVA_HOME' environment variable. Try setting it manually.

It changed to the error. Since it means "I don't have Java", I started building from Java installation.

Java reinstallation

Java 6 is temporarily suspended. (* Because it is used only with Adobe CS6 and there are no plans to use the CS6 apps in the near future)

Java 8 installation

Run brew cask install java8.

At Cordova

This is the result of running cordova run android.

result


CordovaError: Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle

Without Gradle (build tool) ...

Now that the Java version issue has been resolved, we will continue to build the Android development environment.

... It's quite troublesome.

Summary

Unless I was developing an app, I wasn't really aware of Java, but when I dug into it again, the contents of the machine were unexpectedly messy. Even though it looks refreshing, it is put in and out of this and that. The procedure of fundamentally deleting and rebuilding from scratch like this time must continue to be learned by the organizers.

It's been a long time, but thank you for reading to the end.

Recommended Posts

Reinstall JDK for Cordova
Download the JDK 8 installer for students