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

执行ionic cordova build android报错:Project target does not exist

解决Ionic Cordova构建Android时的"Project target does not exist"错误

问题描述

执行命令ionic cordova build android时触发以下错误:

An unhandled exception occurred: Project target does not exist.
[ERROR] An error occurred while running subprocess ng.

完整错误日志:

[error] Error: Project target does not exist.
    at findProjectTarget (C:\Users\jsaez\Documents\Odec\CTAV\ctav-mobile\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:49:15)
    at Object.getBuilderName (C:\Users\jsaez\Documents\Odec\CTAV\ctav-mobile\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:62:46)
    at WorkspaceNodeModulesArchitectHost.getBuilderNameForTarget (C:\Users\jsaez\Documents\Odec\CTAV\ctav-mobile\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:101:35)
    at RunCommand.runSingleTarget (C:\Users\jsaez\Documents\Odec\CTAV\ctav-mobile\node_modules\@angular\cli\models\architect-command.js:242:55)
    at RunCommand.runArchitectTarget (C:\Users\jsaez\Documents\Odec\CTAV\ctav-mobile\node_modules\@angular\cli\models\architect-command.js:295:35)
    at RunCommand.run (C:\Users\jsaez\Documents\Odec\CTAV\ctav-mobile\node_modules\@angular\cli\commands\run-impl.js:15:25)
    at RunCommand.validateAndRun (C:\Users\jsaez\Documents\Odec\CTAV\ctav-mobile\node_modules\@angular\cli\models\command.js:136:33)
    at async runCommand (C:\Users\jsaez\Documents\Odec\CTAV\ctav-mobile\node_modules\@angular\cli\models\command-runner.js:224:24)
    at async default_1 (C:\Users\jsaez\Documents\Odec\CTAV\ctav-mobile\node_modules\@angular\cli\lib\cli\index.js:70:31)

项目的package.json配置:

{
  "dependencies": {
    "@ionic/angular": "^6.0.0",
    "@ionic/cordova-builders": "^7.0.0",
    "@ionic/storage": "^3.0.6",
    "@ionic/storage-angular": "^3.0.6",
    "ionic-cache": "^6.0.3"
  },
  "cordova": {
    "plugins": {
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-ionic-keyboard": {}
    },
    "platforms": [
      "android"
    ]
  }
}

解决方案

1. 检查并修复angular.json中的Target配置

错误核心是Angular CLI找不到对应的构建target,需检查项目根目录下的angular.json文件:

  • 定位到projects -> [你的项目名称] -> architect节点
  • 确认是否存在cordova-build和cordova-serve配置项,示例配置如下(将app替换为你的项目实际名称):
"cordova-build": {
  "builder": "@ionic/cordova-builders:cordova-build",
  "options": {
    "browserTarget": "app:build"
  },
  "configurations": {
    "production": {
      "browserTarget": "app:build:production"
    }
  }
},
"cordova-serve": {
  "builder": "@ionic/cordova-builders:cordova-serve",
  "options": {
    "cordovaBuildTarget": "app:cordova-build",
    "devServerTarget": "app:serve"
  },
  "configurations": {
    "production": {
      "cordovaBuildTarget": "app:cordova-build:production",
      "devServerTarget": "app:serve:production"
    }
  }
}

若缺失上述配置,手动添加即可。

2. 对齐依赖版本

当前@ionic/angular为6.x版本,但@ionic/cordova-builders是7.x版本,两者版本不兼容(7.x builders对应Ionic 7+)。执行以下命令降级builders:

npm install @ionic/cordova-builders@6.2.0 --save-dev

3. 清理依赖并重新安装

执行以下命令清理缓存并重装依赖:

  • Linux/macOS:
rm -rf node_modules package-lock.json
npm install
  • Windows:
rmdir /s node_modules
del package-lock.json
npm install

4. 重新添加Android平台

先移除现有Android平台,再重新添加:

ionic cordova platform remove android
ionic cordova platform add android

完成以上步骤后,再次执行ionic cordova build android即可解决错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 00:40:26