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

执行$cordova build android命令出现退出码1错误,寻求技术协助

Fixing "Error: cmd: Command failed with exit code 1" in Cordova Android Build

Hey there, this error is super common when building Cordova Android projects, but it’s almost always a fixable issue tied to environment setup, dependencies, or project configuration. Let’s walk through the most likely fixes step by step:

1. Verify Your Android SDK Environment Variables

First, double-check that your system has the correct Android SDK paths configured:

  • Open Command Prompt and run echo %ANDROID_HOME% (or echo %ANDROID_SDK_ROOT% for newer SDK installations) — it should return the full path to your Android SDK folder (like C:\Users\YourName\AppData\Local\Android\Sdk).
  • Next, run adb version — if this throws an error, your platform-tools folder isn’t in your system PATH. Add %ANDROID_HOME%\platform-tools and %ANDROID_HOME%\tools to your system environment variables, then restart your Command Prompt to apply changes.

2. Check Cordova & Android Platform Compatibility

Mismatched versions between Cordova and the Android platform often trigger this generic error:

  • Update Cordova to the latest stable version first:
    npm install -g cordova@latest
    
  • Then remove and re-add the Android platform with a compatible version (Android 12 is a reliable stable choice for most projects):
    cordova platform remove android
    cordova platform add android@12.0.0
    
    You can check compatible platform versions for your Cordova release by running cordova platform ls to see available options.

3. Clean Corrupted Project Caches

Build caches get corrupted all the time—clear them out with these steps:

cordova clean

You can also manually delete the platforms/android/build folder on Windows (or rm -rf platforms/android/build on macOS/Linux) to ensure a fresh build environment.

4. Get the Full Error Log (Critical!)

The "exit code 1" message is just a generic failure notice—you need the detailed log to find the actual root issue. Run the build in verbose mode to see the full output:

cordova build android --verbose

Look for lines starting with ERROR or FAILURE — this will point you directly to the problem, like:

  • A missing Android SDK component (e.g., you need to install the Android 12 SDK via the SDK Manager)
  • A dependency that failed to download (check your internet connection, or switch to a mirror if needed)
  • A conflicting or outdated plugin

5. Fix Path & Permission Issues

  • Avoid special characters in your project path: Cordova struggles with spaces, Chinese characters, or symbols in folder paths. Move your project to a simple, plain-text path like C:\CordovaProjects\MyApp.
  • Run Command Prompt as Administrator: Some build processes require write access to system folders—right-click Command Prompt and select "Run as administrator" before initiating the build.

If you run the verbose build and still can’t pinpoint the specific error, post that detailed log snippet, and we can dive deeper into troubleshooting!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:48:18