ionic 2 - Error Could not find an installed version of Gradle either in Android Studio
Asked Answered
H

22

220

I create ionic 2 project and add diagnostic cordova plugin like this :

ionic plugin add cordova.plugins.diagnostic

npm install --save @ionic-native/diagnostic

and add android platform like this :

ionic platform add android@latest

but when build with ionic build android console give me this error :

Error: 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

and I try to download manualy gradle.3.3-all.zip and change this distributionUrl var in platform/android/cordova/lib/builders/GradleBuilder.js

 var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-3.3-all.zip'

to:

var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'file:///E:/gradles/gradle-3.3-all.zip';

but not working and console give me last error.

I dont know how to add gradle for android@latest version

Highminded answered 18/4, 2017 at 18:52 Comment(7)
Do you have android sdk properly installed?Intumescence
yes ,this problem solve with define gradle in path system variable , but when run build android ,console give me :"You have not accepted the license agreements of the following SDK components" errorHighminded
You have to install the proper sdk version (via android sdk manager) and accept the terms. forum.ionicframework.com/t/…Intumescence
did you solve this issue? I have the same problemInainability
yes ,I download gradle.zip manually and include it into path.Highminded
Similar issue try this -> Window, Linux & MacOS users - Install Gradle manuallyCeltic
You will also get this error if you are on Windows and your project path has parenthesis in it. eg. "cordova(something)". (At least until this issue is fixed.)Corduroys
S
155

Try installing gradle and include it into your path. Click the link below to get manual. https://gradle.org/install

Scimitar answered 29/4, 2017 at 5:15 Comment(4)
Thanks! Rediculous that cordova / ionic still hasn't fixed this.Americanism
If you have Android studio and a project using gradle, you can find it for example like: ~/apps/android-studio$ find . -type f -name gradle ./gradle/gradle-4.1/bin/gradle. Sorry for markup, it's the comment. So you could add that to your PATH variable but you will need to keep that version installed.Ranjiv
Yes, I found one, added to the path and it worked like a charm, thanks. > export PATH=$PATH:/Users/MyUser/.gradle/wrapper/dists/gradle-4.1-all/xxx/gradle-4.1/binTransvestite
don't forget to reboot your computer (windows)Eduino
D
280

Life is too short to spend it on messing with paths, etc.

Since I had Homebrew installed on the iMac, I just ran this command:

brew install gradle

The Ionic3 project started to build successfully.

Dialecticism answered 24/5, 2017 at 14:28 Comment(7)
brew update && brew install gradle -- otherwise gradle doesn't install if brew needs to update first.Howlond
Worked for me running Cordova CLI without Ionic. Plus I didn't have to do the double line to get gradle to install as mentioned in Kit's comment. Very happy - simple solution. Thanks so much @AFD !!!!Burrill
@Howlond brew auto updates when you run brew install nowadaysEversion
"Life is too short to spend it on messing with $complicated_topic" will be my new ace up my sleeve at a job interview.Surfbird
thanks much.. gr8 help..very true that "life is too short to spend it on messing..."Clothe
I know have 3(?) versions of jdk and gradle on my machine....but it works now so... okFreddyfredek
But Android Studio already includes Gradle, so why isn't it recognised?Income
S
155

Try installing gradle and include it into your path. Click the link below to get manual. https://gradle.org/install

Scimitar answered 29/4, 2017 at 5:15 Comment(4)
Thanks! Rediculous that cordova / ionic still hasn't fixed this.Americanism
If you have Android studio and a project using gradle, you can find it for example like: ~/apps/android-studio$ find . -type f -name gradle ./gradle/gradle-4.1/bin/gradle. Sorry for markup, it's the comment. So you could add that to your PATH variable but you will need to keep that version installed.Ranjiv
Yes, I found one, added to the path and it worked like a charm, thanks. > export PATH=$PATH:/Users/MyUser/.gradle/wrapper/dists/gradle-4.1-all/xxx/gradle-4.1/binTransvestite
don't forget to reboot your computer (windows)Eduino
E
113

Just install gradle on linux, Even if Android Studio is installed,

sudo apt install gradle

Elm answered 11/5, 2017 at 8:1 Comment(1)
If you are linux user e.g. ubuntu and you are try to run cordova run android command at that time this commad will helpPollerd
B
110

For windows users:

Download gradle binary from the link in the answer Gradle Download

Extract the zip file to 'C:\Gradle' or somewhere else

open Edit Environment variable dialog from start menu > Search

Click 'New' under system variables and add as below

Variable Name GRADLE_HOME Variable Value C:\Gradle\gradle-4.0.1

Then choose PATH variable from system variable list

append the gradle path to variable value like this C:\Gradle\gradle-4.0.1\bin

then press win Key+R type cmd then enter > in command terminal type gradle -v

if the setup is correct you will see the gradle installation details

Bumboat answered 13/7, 2017 at 3:11 Comment(2)
can i have gradle download linkBaronet
Gradle download from here: gradle.org/releasesChavez
E
27

I was already installed Android Studio and it's just need to add gradle PATH to ~/.bash_profile on my MacOSX Mojave. Also if gradle is upgraded then path might need to update again.

Example .bash_profile :

export ANDROID_SDK_ROOT="~/Library/Android/sdk"
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export JAVA_HOME=$(/usr/libexec/java_home)
export GRADLE_PATH="~/.gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/gradle-4.10.1/bin"
export ANDROID_STUDIO="/Applications/Android Studio.app/Contents/MacOS"
export PATH="$PATH:$GRADLE_PATH:$ANDROID_STUDIO"

When edited your .bash_profile then run a command below to read it again.

source ~/.bash_profile
Economic answered 16/4, 2019 at 7:42 Comment(4)
I was able to use this method to find my own gradle path and insert it. Thank you.Boor
How did you find the gradle path? Android Studio is supposed to have installed gradle but it's not being found by Cordova requirements. Or is it just an adaptor that Android Studio installs for gradle?Income
I forgot it now. Did you find it in ~/.gradle/wrapper/dists/ ?Economic
Adding GRADLE_PATH didn't solve for me.Austere
D
18

For Windows you can try below solution

Copy your gradle-->bin path and add it to system environment variable path.

In my case gradle path is

C:\Users\username\.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9\gradle-3.3\bin

This solution worked for me.

Diapason answered 28/3, 2019 at 4:16 Comment(3)
Thank you - this seems to me a much better solution that installing yet another version of Gradle on your computer.Kilmarnock
Don't forget to start a new session of CMD after adding to pathPorcupine
I guess this is pretty obvious but if you upgrade the Gradle in Android Studio then you're going to have to re-add the path.Kilmarnock
S
14

In Ubuntu, Installing latest version of gradle solved the issue for me.

Try these steps to install the latest version,

sudo add-apt-repository ppa:cwchien/gradle

sudo apt-get update

sudo apt-get install gradle

then build using,

cordova build android or ionic cordova build android

Note: If you install gradle from ubuntu repo, it will install the old version 1.4 and will not help, so sudo apt-get install gradle alone will not help most times, if you did not add the repo ppa:cwchien/gradle earlier

Sizar answered 13/5, 2017 at 18:49 Comment(0)
A
13

There is a problem with cordova version 6.4.0 and android 6.2.1 .so,please try with below compatible versions

cordova version must be 6.4.0

sudo npm install -g [email protected]

Install android in your project

sudo cordova platform add [email protected]

 or

sudo ionic platform add [email protected]

Adhesive answered 20/4, 2017 at 7:49 Comment(4)
You really shouldn't run npm with sudo!Fugal
if your system ask permissions then you need to use sudoAdhesive
If you set it up right, it doesn't need permissions. You download untrusted code that can execute automatically. This should not be done with elevated permissions! See docs.npmjs.com/getting-started/fixing-npm-permissionsFugal
Simply paste this line sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share} before first command and remove sudo.Iila
G
10
brew install gradle

In short that will save time :) Ionic team please fix this

Graben answered 27/4, 2020 at 19:53 Comment(0)
K
6

On Ubuntu 18.04, I intalled gradle with:

sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle

And Ready.

Kohima answered 29/11, 2018 at 14:53 Comment(2)
Do you really need the first line on Ubuntu 18.04?Beulahbeuthel
Hello Joe, good question, in Ubuntu repositories the version is 3.4.1 but in repository ppa:cwchien/gradle the version is 5.0. Is not really necessary to use the first line, but is important to install the last version.Kohima
P
4

I would like to add my two cents to this conversation. If you are a Windows user, you would like to take advantage of Chocolatey

Per https://community.chocolatey.org/packages/gradle, you need to run in your console (it assumes you already have Chocolatey installed).

choco install gradle

If you haven't installed Chocolatey, follow the instructions at https://chocolatey.org/install

Probst answered 2/7, 2021 at 15:9 Comment(0)
L
3

If you dont want to install gradle explicitly just to address this issue, you can overcome this by following the workaround as mentioned below:

  1. Look for check_reqs.js file under platforms\android\cordova\lib folder
  2. Edit the else part of androidStudioPath variable null check in get_gradle_wrapper function as below:

Existing code:

else { //OK, let's try to check for Gradle! return forgivingWhichSync('gradle'); }

Modified code:

else { //OK, let's try to check for Gradle! var sdkDir = process.env['ANDROID_HOME']; return path.join(sdkDir, 'tools', 'templates', 'gradle', 'wrapper', 'gradlew'); }

NOTE: This change needs to be done everytime when the android platform is removed and re-added

UPDATE: The above workaround will work fine till Cordova Android version 6.3.0. For Cordova Android 6.4.0 and above, Gradle needs to be installed as a standalone dependency. Please find Cordova Android 6.4.0 release notes for more info on this.

Lylalyle answered 16/6, 2017 at 15:20 Comment(7)
Could someone let me know why this answer is downvoted?Lylalyle
it does not solve problem, install gradle and set pathBumboat
@Bumboat have tried it in my cordova CLI and it works after this tweak. Could you explain what excatly you tried and what failed?Lylalyle
ok, but i dint downvote, i tried ur solution but it dint wrk, after installing gradle and setting path variable it workedBumboat
@Bumboat check this out where the answer is accpeted - #43357333Lylalyle
This answer does solve the problem, but only for Cordova-Android plugin version below 6.3.0.Credence
@TashPemhiwa You are absolutely right. Updated the answer.Lylalyle
T
3

For Windows users:

Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
scoop install gradle
Turning answered 17/5, 2018 at 10:0 Comment(0)
U
3

Just install the Gradle through the command line If you are using Mac try

brew install gradle
Unchurch answered 7/9, 2018 at 8:47 Comment(0)
P
2

I am on Microsoft Windows:

I encountered this error after upgrading Android Studio from 2.3.3 to 3.0. I solved it by changing the path to gradle in the PATH environment variable, which is now "gradle-4.1" for Android Studio 3.0 (previously it was "gradle-3.2" for Android Studio 2.3.3)

Positronium answered 8/11, 2017 at 8:34 Comment(0)
F
2

I moved Android folder path to another path and taked this error.

I resolved to this problem in below.

I was changed to Gradle path in system variables. But not path in user variables. You must change to path in system variables

Screenshot this

Alternative Screenshot this

Fubsy answered 15/1, 2019 at 21:19 Comment(0)
Q
1

First of all uninstall ionic and cordova, later set your variables envarionment JAVA_HOME, ANDROID_HOME and PATH then reinstall ionic cordova and add platform like follow:

$ sudo npm install -g ionic cordova

$ ionic platform add android

The ionic will setup gradle packages properly.

Quicklime answered 20/4, 2017 at 13:20 Comment(1)
My edit was rejected... so I post as a comment : the npm keyword is missing after sudo in the first line of your code.Morphophoneme
C
1

I solve this problem

Download gradle.zip from this site https://gradle.org/install. And follow the instructions indicated in the site.

Then open another terminal cmd and execute the command:

Cordova build android --prod --release
End
Cohberg answered 4/6, 2017 at 12:3 Comment(0)
M
1

In Arch Linux/Manjaro: sudo pacman -S gradle

Megalopolis answered 18/8, 2017 at 19:15 Comment(0)
G
0

just install android studio and select your sdk folder as a android studio's sdk default folder and then android studio repair all the damage area and download needed files.

Gillette answered 14/6, 2017 at 7:14 Comment(0)
A
0

Download the latest gradle from https://gradle.org/install and set the gradle path upto bin in your PATH variable and export path in the directory you are working in

example : export PATH=/home/abc/android-sdk-linux/tools:/home/abc/android-sdk-linux/platform-tools:/home/abc/android-sdk-linux/tools:/home/abc/android-sdk-linux/platform-tools:/home/abc/Downloads/gradle-4.4.1/bin

I spent my whole day resolve this and ultimately this solution worked for me,

Arlinearlington answered 23/12, 2017 at 6:4 Comment(0)
P
0

If your gradle was working normally before and this came up (probably after you upgraded or reinstalled ionic or cordova - as was my case), you might want to leave the environment variable as is, and check if the folder listed there actually exists.

If it doesn't, rather than reinstalling gradle as mentioned above and changing the value of the environment variable, I had to recreate the old missing folder and copy the gradle files into them.

It seems the value of the gradle location is saved somewhere in Android Studio, and updating the PATH in system variables doesn't affect Android Studio checking for that same location after something triggers a change.

Porcupine answered 25/5, 2021 at 19:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.