执行$cordova build android命令出现退出码1错误,寻求技术协助
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%(orecho %ANDROID_SDK_ROOT%for newer SDK installations) — it should return the full path to your Android SDK folder (likeC:\Users\YourName\AppData\Local\Android\Sdk). - Next, run
adb version— if this throws an error, yourplatform-toolsfolder isn’t in your systemPATH. Add%ANDROID_HOME%\platform-toolsand%ANDROID_HOME%\toolsto 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):
You can check compatible platform versions for your Cordova release by runningcordova platform remove android cordova platform add android@12.0.0cordova platform lsto 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

