简体   繁体   中英

Cordova picking up wrong version of java

I am trying to run

cordova build android

It gives the following error

Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/home/bappaditya/Softwares/android-studio (recommended setting)
ANDROID_HOME=/home/bappaditya/Softwares/android-studio (DEPRECATED)
Requirements check failed for JDK 8 ('1.8.*')! Detected version: 12.0.2
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.

I can see that it has picked up ANDROID_HOME and ANDROID_SDK_ROOT but not the correct version of java

My current environment

>java -version
openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)

>echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64

>echo $PATH
/home/bappaditya/.cargo/bin:/opt/gradle/gradle-5.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/bappaditya/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin

As you can see the JAVA 8 is installed and set as default. Why cordova complaining about java version?

It seems cordova uses javac to identify the version and not java .

So the command that really shows the version cordova gets when looking for Java is:

javac -version

In my case, even though I had identical versions to what you have in your environment, it turned out my javac was pointing to a newly updated Java (from Ubuntu updates)

To fix it, I used the update-alternatives command and set javac back to my 1.8.0 version as follow:

sudo update-alternatives --config javac

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM