无法构建Cordova应用:JDK版本检测失败问题求助
Fix: JDK 1.8.2 Requirement Error in Ionic 3 + Cordova (With JDK 9 Installed)
Why This Happens
I've run into this exact snag back when working with Ionic 3 and older Cordova versions—here's the deal: Ionic 3 and its dependent Cordova tooling have strict compatibility with JDK 8 (1.8.x). JDK 9 introduced breaking changes to APIs and module systems that the older build tools simply don't support, which is why you're hitting the requirement check failure even with a newer JDK installed.
Solutions to Try
1. Install JDK 8 and Set It as Default (Recommended)
This is the most reliable fix since it aligns perfectly with what the tooling expects:
- Grab JDK 8 (either Oracle JDK 8 or OpenJDK 8 works) and install it on your system.
- Configure your environment variables:
- Set
JAVA_HOMEto the installation path of JDK 8 (e.g.,C:\Program Files\Java\jdk1.8.0_xxxon Windows,/Library/Java/JavaVirtualMachines/jdk1.8.0_xxx.jdk/Contents/Homeon macOS). - Add the JDK 8
bindirectory to the front of yourPATHvariable to make sure it takes priority over JDK 9.
- Set
- Verify the change: Open a fresh terminal/command prompt and run:
Both should output a version starting withjava -version javac -version1.8.x.
2. Switch Between JDK Versions (If You Need JDK 9 for Other Projects)
If you don't want to uninstall JDK 9, you can set up quick version switching:
- Windows:
- Create environment variables like
JAVA_HOME_8(pointing to JDK 8) andJAVA_HOME_9(pointing to JDK 9). - Use a batch script to toggle
JAVA_HOMEandPATHwhen working on your Ionic 3 project, or manually edit the environment variables temporarily.
- Create environment variables like
- macOS/Linux:
- Add aliases to your shell config file (e.g.,
~/.bashrc,~/.zshrc) to switch fast:alias jdk8='export JAVA_HOME=/path/to/jdk8' alias jdk9='export JAVA_HOME=/path/to/jdk9' - Run
jdk8in your terminal before building the Ionic app to use JDK 8 for that session.
- Add aliases to your shell config file (e.g.,
3. Double-Check Cordova and Android SDK Compatibility
While the JDK version is the main culprit, keep in mind Ionic 3 is an older framework:
- Make sure your Android SDK targets a compatible version (typically Android 8.0/8.1, SDK level 26 or 27).
- Skip the latest Android SDK tools—they often don't play nice with older Cordova versions.
内容的提问来源于stack exchange,提问作者Nitrof
相关产品推荐
相关产品推荐

