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

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\.gradle and delete the entire directory.
  • Verify your Gradle environment setup:
    1. 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.
    2. Add a GRADLE_HOME system environment variable pointing to that folder.
    3. Add %GRADLE_HOME%\bin to your system PATH.
    4. Test it by opening a new command prompt and running:
      gradle -v
      
      You should see the Gradle version output without errors.

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/android folder and open the local.properties file. Confirm the sdk.dir path 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_modules folder and package-lock.json file from your project root.
  • Run npm install to reinstall dependencies.
  • Repeat the platform remove/re-add steps from section 1.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:48:45