构建Ionic Android应用时遇Cannot read property '1' of null错误求助
Hey there! I’ve seen this exact error pop up when there’s a mismatch between your Cordova version and JDK setup, so let’s break this down and fix it together.
问题根源
Your setup has a critical compatibility issue: Cordova 6.0 does not support JDK 10.1. Cordova 6.x was released back when JDK 8 was the standard, and it can’t handle the versioning changes introduced in JDK 9+. That "Cannot read property '1' of null" error is Cordova’s way of failing to parse the newer JDK version information.
分步解决方案
- 降级JDK到版本8: This is the core fix. Uninstall JDK 10.1 and install JDK 8 (either Oracle JDK 8 or OpenJDK 8 works—just make sure it’s a full JDK, not just JRE).
- 更新环境变量配置:
- Set
JAVA_HOMEto point to the root directory of your JDK 8 installation (e.g.,C:\Program Files\Java\jdk1.8.0_301on Windows,/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Homeon Mac). - Add the JDK 8
binfolder to your systemPATHvariable to ensure the CLI picks up the correct version.
- Set
- 验证JDK版本: Open a fresh terminal/command prompt and run
java -versionandjavac -version—both should show version 1.8.x. - 清理并重新构建项目:
- Run
ionic cordova clean androidto clear cached build files that might be causing conflicts. - Try rebuilding with
ionic cordova build androidagain.
- Run
- 检查Android SDK兼容性: Cordova 6.0 works best with Android SDK Build Tools versions between 23.x and 26.x. Open Android Studio’s SDK Manager and make sure you have one of these versions installed.
If you still hit snags after these steps, double-check that your Ionic 3 and Cordova 6.x versions are in sync (they’re designed to work together, so this shouldn’t be an issue, but it’s worth confirming).
内容的提问来源于stack exchange,提问作者Amit Anand

