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)

Most upvoted comments

On another PC (with a newer version of Android Studio) there is no gradle folder in C:\Program Files\Android\Android Studio. It looks like that the setup has been changed. In the Android Studio settings Build, Execution, Deplayment > Gradle you can see the “service directoy”. In my case it’s %USERNAME%\.gradle.

In the .gradle folder there is a wrapper\dist folder. There may be several versions. In my case gradle-4.10.3-all and gradle-5.4.1-all. Each folder has a random id like 81msde2dx9p4vji0mjgtvxkcb. (random or id / hash?). Inside and a few folder deeper you can find the bin 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.

$ cordova build
....
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=..../android-sdk (recommended setting)
ANDROID_HOME=..../android-sdk (DEPRECATED)
Using Android SDK: ..../android-sdk

Welcome to Gradle 6.6.1!

Here are the highlights of this release:
 - Experimental build configuration caching
 - Built-in conventions for handling credentials
 - Java compilation supports --release flag

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

Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 3s
1 actionable task: 1 executed
Subproject Path: CordovaLib
Subproject Path: app
Starting a Gradle Daemon (subsequent builds will be faster)

> Task :app:compileDebugJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 14s
40 actionable tasks: 40 executed
Built the following apk(s): 
        ..../platforms/android/app/build/outputs/apk/debug/app-debug.apk

Workaround: I installed gradle 6.1 to C:\Gradle and added C:\Gradle\bin to my PATH environment variable.

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 with gradle- then pick it’s first sub-folder (hash) then inside this hash sub-folder pick first sub-dir starting with gradle-

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