Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

android - 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?

question from:https://stackoverflow.com/questions/65933541/cordova-picking-up-wrong-version-of-java

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...