Encountering an error can be very stressful. Having made your coffee, headphones on, and ready to make the best application the world has seen, then boom, getting an error from the first step. Today we tackle how to fix the could not find gradle
error.
Challenge
When you try to build your Ionic application using Cordova command:
$ ionic cordova run android
You may encounter an error with the message:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:Users\codeswag.co.uk\AppData\Local\Android\Sdk (DEPRECIATED)
could not find an installed version of Gradle either in Android Studio,
or on your system to the install gradle wrapper. Please include gradle
in your path, or install Android Studio
[ERROR] An error occurred while running subprocess cordova
Solution
The first thing we need to do is head over to the Gradle website. When we land on the Gradle website, we want to:
- Click the
Install Gradle
button. -
Scroll down to the install manually section and click on the
Download
link. -
Scroll down to the latest version, and here we will download
binary-only
.
Our download begins.
Installation
- When our download is complete, we want to paste the downloaded zip file onto our
C:
drive. ClickContinue
to confirm pasting intoC:
drive. -
Next, we want to extract the file. Right-click on the zip file and select
Extract All
. -
It shows us the destination of our extraction. click
Extract
. -
Next, we now want to delete our zip file in the C Drive and then rename our extracted file to simply
gradle
. -
Click inside the
gradle folder
, and you can see we have the specific version of the Gradle we downloaded,gradle-7.5.1
. -
The next step is we want to go to this PC, right-click on it, and select
Properties
. -
We want to go to
Advanced system settings
. Here it is on the right hand side underRelated settings
. -
Next, click where it says
Environment Variables
. -
We want to go to the
System Variables
section and selectPath
, and with thePath
highlighted, we want to clickEdit
. -
Next, we want to add the path to the binary folder highlighted below into our
Environment Variables
.C: \ gradle \ gradle-7.5.1 \ bin
To get the path we need, in the gradle-7.5.1 folder, open the
bin
folder, head to theaddress bar
and copy the address to the folder.You need to be inside the bin folder.
-
Now back here on our system path, we will select
New
. -
Paste the path to the gradle bin folder and select
Ok
. -
We are done. Time to exit, Select
Ok
. -
Select
Ok
once again.
Our gradle is now in the path variable. We have to restart our machine to apply the changes.
After restarting your machine, head back to the command line and retype to see the gradle installed:
$ gradle -v
Gradle is now working.
We will clear the screen and then try to run our ionic Cordova application using the Android Emulator. We do that with the following command:
$ ionic cordova run android
Here we see the build is succesful and we are no longer getting the gradle missing error message.
The emulator has booted up, and there we have our app running.
There is not much in terms of the application but this is a successful demonstration of how to deal with the could not find gradle
error in ionic.
Conclusion
After successfully installing gradle and you try to build the application, you may run into other errors. You must remove and reinstall your Android Cordova platform to resolve those errors.
To do that, you use the command:
$ ionic cordova platform rm android
And this will remove the Android platform, and when you want to add it back, you will use the command:
$ ionic cordova platform add android
Recent Comments