[Cordova] 用 Cordova 編譯 Android app 時找不到 Gradle?

[Cordova] 用 Cordova 編譯 Android app 時找不到 Gradle?

Cordova 和 Gradle 真的是很常遇到問題…

上次用 Cordova 編譯還好好的,

今天執行 cordova compile 就出現找不到 Gradle 的錯誤:

(node:51122) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): 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

 

網路上找了半天,有人說是環境變數 PATH 之類的問題,

不過另一種較簡單的解法是直接裝一個 Gradle…

在 Mac 上直接用 Homebrew 安裝:

brew install gradle

 

裝好之後,先執行一次 gradle 看看:

testuser@localhost ~ $ gradle

Welcome to Gradle 4.8!

Here are the highlights of this release:
 - Dependency locking
 - Maven Publish and Ivy Publish plugins improved and marked stable
 - Incremental annotation processing enhancements
 - APIs to configure tasks at creation time

For more details see https://docs.gradle.org/4.8/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> Task :help

Welcome to Gradle 4.8.

To run a build, run gradle  ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

To see more detail about a task, run gradle help --task 

For troubleshooting, visit https://help.gradle.org

BUILD SUCCESSFUL in 4s
1 actionable task: 1 executed

 

再重新執行 cordova compile,Gradle 找不到的問題就消失囉~

 

參考資料:ionic 2 – Error Could not find an installed version of Gradle either in Android Studio

(本頁面已被瀏覽過 2,591 次)

2 thoughts on “[Cordova] 用 Cordova 編譯 Android app 時找不到 Gradle?

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料