cordova-android: Can't find Gradle (Android Studio)
Bug Report
Problem
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.
What is expected to happen?
Just work. The message is wrong. Android Studio is already installed. Leave a link to the docs for this problem. Because everything is correctly setup (by the message). Also the enviroment path variables are set.
What does actually happen?
The Android Studio is installed and I can use it. I already installed a apk by the Studio and Flutter. But Cordova does not work.
Information
The whole Android enviroment and JDK 1.8 (8), Ionic, Cordova etc. are installed. I can run Android apps on my physical phone. e.g. using Flutter and the Android Studio. It’s always tortuous to bring Cordova Android to get running.
Command or Code
ionic cordova run android
Environment, Platform, Device
Running Cordova 9 with native-run of Ionic 4 on Windows 10 64bit.
Version information
Click to expand
Ionic:Ionic CLI : 5.2.5 Ionic Framework : @ionic/angular 4.9.0 @angular-devkit/build-angular : 0.801.3 @angular-devkit/schematics : 8.1.3 @angular/cli : 8.1.3 @ionic/angular-toolkit : 2.0.0
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1) Cordova Platforms : android 8.0.0
Utility:
cordova-res : not installed native-run : 0.2.8
System:
NodeJS : v10.16.3 npm : 6.9.0 OS : Windows 10
Checklist
- I searched for existing GitHub issues
- I updated all Cordova tooling to most recent version
- I included all the necessary information above
Workaround
Install Gradle manually. Maybe the latest Android Studio does not include it for external usage. Whatever… Cordova should remove it from the error text. Because it’s not solved by installing the Android Studio. In my case I already had and set up the environment variables. But still not worked.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 18
- Comments: 32 (12 by maintainers)
On another PC (with a newer version of Android Studio) there is no
gradle
folder inC:\Program Files\Android\Android Studio
. It looks like that the setup has been changed. In the Android Studio settingsBuild, Execution, Deplayment > Gradle
you can see the “service directoy”. In my case it’s%USERNAME%\.gradle
.In the
.gradle
folder there is awrapper\dist
folder. There may be several versions. In my casegradle-4.10.3-all
andgradle-5.4.1-all
. Each folder has a random id like81msde2dx9p4vji0mjgtvxkcb
. (random or id / hash?). Inside and a few folder deeper you can find thebin
folder and the bat file etc.Summary it’s a bit more difficult to find the Gradle stuff for Cordova. 😕
Torturous indeed
Workaround: Create a symlink to the new directory using an Administrator command prompt.
mklink /J "C:\Program Files\Android\Android Studio\gradle" "%USERPROFILE%\.gradle\wrapper\dists\gradle-5.6.4-all\ankdp27end7byghfw1q2sw75f\"
Why has this not been fixed in Cordova?? Every 6 months I come back to use Cordava and it’s broken… Who is maintaining it? 2-8-2020 - In hind site I understand that a lot of work is voluntary so - bit harsh…
I think there simply is no more gradle bin anymore, its a .jar in android-studio/plugins/gradle/lib and cordova is not uptodate with that change. When i add the android platform, open android studio and import exisitng gradle project i can build and run my cordova app for one time. Then when I need to do a cordova build because of the changes its complaining about the gradle bin. So there does not sem to be another way than install gradle standalone and work with its bin.
I had to rebuild my development workstation and I revisited the topic on Linux.
I’m finding that android-studio-ide-183.5692245-linux.tar.gz Android Studio v3.4.2 works fine with Cordova CLI 10.0.0. Android Studio v3.4.2 builds the App for API 29/30 and the artifacts are ok for the upcoming Google Play November deprecation (when Apps built with previous API versions are not going to be accepted anymore).
The following Android Studio versions (v3.5.3, v3.6.3 and v4.0.2) don’t have gradle as a standalone executable. However, the latest Android Studio v4.0.2 can be downloaded and installed to configure the general environment; and then, install
gradle-6.6.1-bin.zip
in an external folder and add it to the path. cordova detects that the gradle executable is in the path and builds the app.Do note that android studio doesn’t officially support gradle 6 (although still may work just fine)
See https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
check_reqs.js for Windows should check
if androidStudioPath === null
in line 113 and if so check if dir%USERPROFILE%\.gradle
exists as it gets created by Android Studio when it opens a project and downloads gradle (version at the time of the comment is 5.4.1). Then check_reqs.js for Windows should search%USERPROFILE%\.gradle\wrapper\dists
for first sub-dir starting withgradle-
then pick it’s first sub-folder (hash) then inside this hash sub-folder pick first sub-dir starting withgradle-
Cordova won’t like gradle 5 during build process so it will download version 4.10.3 to
%USERPROFILE%\.gradle\wrapper\dists
and then start it’s daemon.Installing gradle to
C:\Program Files\Android\Android Studio\gradle\gradle-4.10.3
does the trick, but it wastes 210MB