8
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

Organization

ビルド時にCould not find an installed version of Gradle either in Android Studio...が出る場合の対処法

はじめに

Cordova 8.0.0
Android Studio 3.2 Preview
cordova-android 7.0.0

cordova build androidを実行した時にエラーが発生した。

cordova build android
Android Studio project detected
ANDROID_HOME=/Users/bin/android-sdk/
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
studio
(node:55883) 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
(node:55883) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

cordova emulate androidでもcordova run androidでも同じエラーが出る。
なんかわからんけど、Android Studioのgradleが発見できないみたい。以下で解決した。

以下を.profileに追加してgradleのパスを通す

export PATH="/Applications/Android Studio 3.2 Preview.app/Contents/gradle/gradle-4.5/bin":$PATH

設定を反映する

source ~/.profle
gradle -v
------------------------------------------------------------
Gradle 4.5
------------------------------------------------------------

Build time:   2018-01-24 17:04:52 UTC
Revision:     77d0ec90636f43669dc794ca17ef80dd65457bec

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_101 (Oracle Corporation 25.101-b13)
OS:           Mac OS X 10.13.3 x86_64

gradleのパスが通ったら再ビルドしてみる。

cordova build android

...(中略)...

BUILD SUCCESSFUL in 10s
47 actionable tasks: 47 executed
Built the following apk(s): 
    /Users/work/test/platforms/android/app/build/outputs/apk/debug/app-debug.apk

正常にビルドできた。

まとめ

cordova platform add androidで追加されるのがcordova-android@7.0.0の場合にこのエラーが出る。

cordova create test com.bathtimefish.test Test
cd test
cordova platform add android@6.2.3
cordova build

とした場合はエラーは出ない。7.0.0からgradleの扱いが変わってるのか?

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
8
Help us understand the problem. What are the problem?