Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

はじめに

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の扱いが変わってるのか?

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした