1. 程式人生 > >ionic升級到3.0之後,在使用命令:ionic cordova build android或者ionic cordova emulate android會提示以下錯誤

ionic升級到3.0之後,在使用命令:ionic cordova build android或者ionic cordova emulate android會提示以下錯誤

(node:4308) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 1): CordovaError: Could not find an installed version of Gradle either
in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
(node:4308) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the
future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. [15:09:32] lint finished in 4.67 s

報錯的原因:
cordova在6.4.0(cordova-android在6.1.2)之後,會要求安裝Gradle,基於Gradle來編譯、打包android。(具體版本號有待考證,但是需要安裝Gradle屬實)

解決辦法:

1、手動下載gradle
gradle-x.x-bin.zip (x.x代表版本)
根據需要下載某一版本
地址: (

https://services.gradle.org/distributions)
我下載的是gradle-4.1

下載完成後,解壓到任意資料夾下

2、新增環境變數
PATH=D:\gradle-4.1\bin

3、關閉cmd

4、開啟cmd,輸入gradle -v,檢視是否安裝成功

5、繼續使用ionic cordova build android。