Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid JAVA_HOME when build with cordova

I am trying to emulate an app on my device with cordova in OpenSuse Leap 42.1.
But when I tried to emulate the app with the cordova run I get the error below:

cordova run
Running command: /home/soufraz/Projects/apps/myproject/platforms/android/cordova/run 
ERROR: Error: Failed to run "java -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: /usr/lib64/jvm/java-1.8.0-openjdk-1.8.0

ERROR running one or more of the platforms: Error: /home/soufraz/Projects/apps/myproject/platforms/android/cordova/run: Command failed with exit code 2
You may not have the required environment or OS to run this project

I have the java installed and the paths set in ~/.profile.
Which is the configuration error in my environment?

Below my .profile:

JAVA_HOME=/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0
export JAVA_HOME

ANDROID_HOME=/home/soufraz/Install/android-sdk-linux
export ANDROID_HOME

PATH=$PATH:$ANDROID_HOME:$JAVA_HOME

Info about java version:

java -version
openjdk version "1.8.0_60"
OpenJDK Runtime Environment (build 1.8.0_60-b27)
OpenJDK 64-Bit Server VM (build 25.60-b23, mixed mode)

And here the list of jvm folder:

ls -l
total 28
lrwxrwxrwx 1 root root 24 Nov 12 11:28 java-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0
drwxr-xr-x 1 root root  6 Nov 12 11:28 java-1.7.0-openjdk-1.7.0
drwxr-xr-x 1 root root  6 Nov 11 17:26 java-1.8.0-openjdk-1.8.0
lrwxrwxrwx 1 root root 21 Nov 11 17:26 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root 27 Nov 12 11:28 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx 1 root root 28 Nov 12 11:28 jre-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0/jre
lrwxrwxrwx 1 root root 27 Nov 11 17:26 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx 1 root root 28 Nov 11 17:26 jre-1.8.0-openjdk -> java-1.8.0-openjdk-1.8.0/jre
lrwxrwxrwx 1 root root 29 Nov 11 17:26 jre-openjdk -> /etc/alternatives/jre_openjdk

[edit] View tree with three levels:

tree -L 3
.
├── java-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0
├── java-1.7.0-openjdk-1.7.0
│   └── jre
│       ├── bin
│       └── lib
├── java-1.8.0-openjdk-1.8.0
│   └── jre
│       ├── bin
│       └── lib
├── jre -> /etc/alternatives/jre
├── jre-1.7.0 -> /etc/alternatives/jre_1.7.0
├── jre-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0/jre
├── jre-1.8.0 -> /etc/alternatives/jre_1.8.0
├── jre-1.8.0-openjdk -> java-1.8.0-openjdk-1.8.0/jre
└── jre-openjdk -> /etc/alternatives/jre_openjdk
like image 440
Rafael Soufraz Avatar asked Nov 26 '15 21:11

Rafael Soufraz


People also ask

Why can’t I use Cordova with Android Studio?

Assuming you have Android Studio installed, the issue is either that Android Studio hasn’t set a global path to Java, or Android Studio is using a newer version of Java than the older version 8 that Cordova is still using.

How to create Java_home and Android_home variables?

Just create JAVA_HOME and ANDROID_HOME variables is "System variables" section. After that something that you may have forgotten is to include those variables in "path" variable existing in "System variables" section as below: screen capture Share Follow answered Jul 23, 2016 at 5:43

How do I add environment variables to the JDK installation path?

Set the value of the environment variable to your JDK (or JRE) installation path as follows: setx -m JAVA_HOME "C:\Progra~1\Java\jdk1.8.0_XX" If the path contains spaces, use the shortened path name. Restart Command Prompt to reload the environment variables then use the following command to check the it's been added correctly. echo %JAVA_HOME%

How do I add Java_home to my environment variables?

setx -m JAVA_HOME "C:\Progra~1\Java\jdk1.8.0_XX" If the path contains spaces, use the shortened path name. Restart Command Prompt to reload the environment variables then use the following command to check the it's been added correctly.


1 Answers

It's a bit of misunderstanding with java-X_X_X-openjdk packages. Especially when you are used to default Oracle notation.

The JDK part is confusing, because OpenJDK is a project of an open-source implementation of the Java Platform and not a JDK - package actually allowing you to develop in Java. (more precise info here: http://openjdk.java.net/install/index.html)

TLDR:

  1. java-X_X_X-openjdk is Oracle's JRE equivalent.

  2. java-X_X_X-openjdk-devel is Oracle's JDK equivalent.

like image 149
Mateusz Was Avatar answered Sep 18 '22 19:09

Mateusz Was