Ionic 运行Android和Java版本离子 cordova

kcrjzv8t  于 2022-12-08  发布在  Ionic
关注(0)|答案(1)|浏览(195)

so I'm basically trying to run my ionic app on an android device, and the command "ionic cordova run android --device" get as far as telling me an error occurred due to:

Requirements check failed for JDK 1.8.x! Detected version: 16.0.0
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.

So, after verifying which java versions I had and successfully changing the version to a 1.8.X, so when I run java -version, it returns:

java version "1.8.0_251"

However, running "ionic cordova run android --device" again, it returns the same original error:

Requirements check failed for JDK 1.8.x! Detected version: 16.0.0
    Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.

After some more research, I realized that the javac version of it, tells me another version, and it needs to be same I believe. So when I run "javac -version", I get:

javac 16

So... I couldn't figure out how to change the javac version to be the same as java, the only thing I figure is that it could be something with PATH, but the topics get a bit confusing as I'm not sure what to do next?
I have in my .zshrc file the following:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Which I added to fix the original java version issue, but that didn't seem to have changed the javac as well.
So after running the commands "which java" and "which javac" respectively, I get:

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java

/usr/bin/javac

I assume there's something funny in here, huh? But this is basically where I'm stuck. I'm not even sure if this is the issue, but it's one of those things I think I'm just doing something stupid without realising it lol
Any help is greatly appreciated!

erhoui1w

erhoui1w1#

Goal

You are describing that you want "java" and "javac" to both resolve to JDK 1.8. From there, you'll be able to use ionic cordova to do things.

Starting point

Here are various commands you've run, along with their output (I changed format to make it look like actual commands being run, and the output):

  • Java compiler ("javac") is for JDK 16, and lives at /usr/bin/javac (which might be an alias to another location).
% javac -version
javac 16

% which javac
/usr/bin/javac
  • Java runtime – the thing which starts the Java Virtual Machine – is resolving somewhere else altogether – /Library/Internet Plug-Ins/... – and shows up as version 1.8, not 16:
% which java
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java

% java -version
java version "1.8.0_251"

A few takeaways..

  • You have JDK 16 installed, resolving to /usr/bin
  • You have something separately installed at "/Library/Internet.." – this is most likely a JRE (not a JDK) , and is version 1.8

Fix

Install JDK 1.8 – this will give you a compiler and runtime that are both version 1.8

  • Follow download steps here: https://www.oracle.com/java/technologies/downloads/#java8 Once installed, you should be able to switch to using JDK 1.8, and confirm versions of both the compiler (javac) and the runtime (java) binaries.
  • There are various ways to set JAVA_HOME and manage multiple JDK installs – this is the simplest way to just get past the issue you're facing: set JAVA_HOME manually. This will be system dependent, but below is an example from my local system.
% export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_341.jdk/Contents/Home
  • Verify that "java" resolves to your new 1.8 install:
% java -version
java version "1.8.0_341"
Java(TM) SE Runtime Environment (build 1.8.0_341-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.341-b10, mixed mode)
  • Verify that "javac" also resolves to your new 1.8 install:
% javac -version
javac 1.8.0_341

If you see anything other than above, something else is going on, and we would need to see more details, including whatever output happened from following the above steps.

相关问题