You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

构建Android最新SDK时Cordova报错:Cannot read property 'find' of null

问题描述

已删除node_modules和plugins目录,执行npm install后,使用ionic cordova build android --verbose命令构建APK/AAB文件用于更新Google Play商店,但构建失败。已尝试升级/降级Angular、Cordova、Java SDK、Android Studio插件、npm、nvm版本等多种方案,仍无法解决。

错误信息

核心构建错误

Cannot read property 'find' of null
TypeError: Cannot read property 'find' of null
at D:\NEW\node_modules\cordova-android\lib\prepare.js:392:49
at Array.forEach (<anonymous>)
at updateProjectSplashScreen (D:\NEW\node_modules\cordova-android\lib\prepare.js:388:7)
at updateProjectAccordingTo (D:\NEW\node_modules\cordova-android\lib\prepare.js:271:5)
at D:\NEW\node_modules\cordova-android\lib\prepare.js:69:21
at async Promise.all (index 0)
[ERROR] 运行子进程cordova时出错。

    cordova.cmd build android --verbose 退出,退出码为1。

    使用--verbose标志重新运行此命令可能会提供更多信息。
ionic:utils-process onBeforeExit handler: 'process.exit' received +0ms
ionic:utils-process onBeforeExit handler: running 2 functions +1ms
ionic:utils-process 终止进程树7504时出错: 错误: 命令执行失败: taskkill /pid 7504 /T /F
ionic:utils-process 错误: 未找到进程"7504"。
ionic:utils-process

(翻译:无法读取null的属性'find',类型错误发生在cordova-android的prepare.js文件中处理启动屏的逻辑里,随后子进程cordova构建失败,终止指定进程时发现进程已不存在)

后续进程终止错误

ionic:utils-process onBeforeExit handler: error from function: Error: Command failed: taskkill /pid 7504 /T /F
 ionic:utils-process 错误: 未找到进程"7504"。
ionic:utils-process
ionic:utils-process     at Process.ChildProcess._handle.onexit   (internal/child_process.js:288:5) {
ionic:utils-process   killed: false,
ionic:utils-process 终止进程树14872时出错: 错误: 命令执行失败: taskkill /pid 14872 /T /F
   ionic:utils-process 错误: 未找到进程"14872"。
ionic:utils-process
(internal/child_process.js:288:5) {
ionic:utils-process   killed: false,
ionic:utils-process   code: 128,
taskkill /pid 14872 /T /F
ionic:utils-process 错误: 未找到进程"14872"。
i(internal/child_process.js:288:5) {
 ionic:utils-process   killed: false,
 ionic:utils-process } +1ms
 ionic:utils-process processExit: exiting (exit code: 1) +2ms

(翻译:构建失败后,系统尝试终止相关进程,但指定的进程ID已不存在,最终进程以退出码1终止)

解决建议
  • 检查config.xml中的启动屏配置,确保所有<splash>标签的src路径正确,引用的资源文件确实存在
  • 删除platforms/android目录,重新添加安卓平台:
    ionic cordova platform remove android
    ionic cordova platform add android@x.x.x  # 替换为项目兼容的稳定版本
    
  • 确认项目根目录下resources/android/splash文件夹中的启动屏图片完整,命名和尺寸符合Cordova要求
  • 执行cordova clean清理缓存后,再重新运行构建命令
  • 检查cordova-android版本与项目依赖的兼容性,锁定到之前能正常构建的版本

内容的提问来源于stack exchange,提问作者user22133605

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 06:43:15