Ionic 3项目执行cordova build android失败,寻求解决帮助
Fixing Ionic 3 Android Build Failure (Gradle & Promise Rejection Issues)
Hey, sorry to hear you’ve been stuck on this for two days—let’s walk through practical fixes to get your build working again. The error points to both a Gradle failure and an unhandled promise rejection in Cordova’s superspawn module, so we’ll tackle both angles:
1. Reset Your Cordova Android Platform
Corrupted platform files are a super common culprit here. Let’s start fresh:
- Remove the existing Android platform:
ionic cordova platform remove android - Re-add a stable Android platform version that plays nice with Ionic 3 (Android 8.1.0 is a safe bet—newer versions often break Ionic 3 compatibility):
ionic cordova platform add android@8.1.0
2. Clear Gradle Cache & Fix Environment
Gradle cache corruption is another frequent issue:
- Delete your local Gradle cache folder: Navigate to
C:\Users\ecantero\.gradleand delete the entire directory. - Verify your Gradle environment setup:
- Download Gradle 4.10.3 (the version recommended for Android platform 8.1.0) and extract it to a folder like
C:\Gradle\gradle-4.10.3. - Add a
GRADLE_HOMEsystem environment variable pointing to that folder. - Add
%GRADLE_HOME%\binto your systemPATH. - Test it by opening a new command prompt and running:
You should see the Gradle version output without errors.gradle -v
- Download Gradle 4.10.3 (the version recommended for Android platform 8.1.0) and extract it to a folder like
3. Fix the Unhandled Promise Rejection
The error mentions an unhandled promise in cordova-common—let’s update that dependency:
- In your project root directory, run:
npm install cordova-common@latest --save-dev - Also, make sure your global Cordova version is compatible with Ionic 3. Update to Cordova 9.0.0 (a stable match):
npm install -g cordova@9.0.0
4. Verify Android SDK Configuration
Double-check your Android Studio setup:
- Open Android Studio and ensure you’ve installed Android 9.0 (Pie) SDK (API level 28)—this is required for Android platform 8.1.0.
- Go to your project’s
platforms/androidfolder and open thelocal.propertiesfile. Confirm thesdk.dirpath points to your correct Android SDK location, like:sdk.dir=C\:\\Users\\ecantero\\AppData\\Local\\Android\\Sdk
Last Resort: Full Dependency Reset
If none of the above works, try a full reset of your project dependencies:
- Delete the
node_modulesfolder andpackage-lock.jsonfile from your project root. - Run
npm installto reinstall dependencies. - Repeat the platform remove/re-add steps from section 1.
内容的提问来源于stack exchange,提问作者Emile Cantero
相关产品推荐
相关产品推荐

