Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK - Android
Asked Answered
L

24

208

I know there are lots of questions similiar to this one, but i couldn't find a solution for my problem in any of those. Besides, I'll provide details for my specific case.

I coded an Ionic project in Ubuntu 16.04 LTS, and now I have to build it for release. So I run the command:

cordova build --release android

And I'm shown the following error:

Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: /home/user/Android/Sdk/tools/templates/gradle/wrapper
  • I don't have this templates/gradle/wrapper directory.
  • My Android Studio is 2.3, the latest version for now
  • Android SDK Platform-Tools 25.0.3
  • Android SDK Tools 25.3.1
  • All Android versions from 2.1 (Eclair) to 7.1.1 (Nougat)

After extensive research, I put all the Android Studio-related environment variables in the file /etc/environment. So now it looks like this:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/game:/home/<user>/Android/Sdk:/home/<user>/Android/Sdk/tools:/home/<user>/Android/Sdk/platform-tools"

ANDROID_HOME=/home/<user>/Android/Sdk
export ANDROID_HOME

JAVA_HOME=/usr/lib/jvm/java-8-oracle
export JAVA_HOME

GRADLE_HOME=/opt/android-studio/gradle/gradle-3.2
export GRADLE_HOME

Now, for the sake of testing the environment variables, I run the following commands:

source /etc/environment
echo $PATH
echo $ANDROID_HOME
echo $JAVA_HOME
echo $GRADLE_HOME

And all the path variables are correctly displayed.

So, it looks like the environment variables are like they should be according to the various similar questions and in tutorials i've searched. Does anyone know what am I doing wrong? Why do I still get the Gradle Wrapper error?

Lagas answered 5/3, 2017 at 20:56 Comment(0)
N
247

I just experienced the same problem.

It may be an occlusion in the instructions regarding how to install (or upgrade) Android Studio with all the SDK Tools which both you and I missed or possibly a bug created by a new release of Studio which does not follow the same file conventions as the older versions. I lean towards the latter since many of the SO posts on this topic seems to point to an ANDROID_PATH with a folder called android-sdk which does not appear in the latest (2.3.0.8) version.

There appears to be a workaround though, which I just got to work on my machine. Here's what I did:

  • Download tools_r25.2.3-windows.zip from Android Downloads.

  • Extracted zip on desktop

  • Replaced C:\Users\username\AppData\Local\Android\sdk\tools with extracted sub-folder tools/

  • In project folder:

    $ cordova platforms remove android
    $ cordova platforms add android

You may also need to force remove the node_modules in android. Hopefully this helps.

Nonperformance answered 7/3, 2017 at 2:32 Comment(14)
THX, I've been trapped in the same phenomenon, now recovered my environment by your remedy. I think it is the fault of Google, so cordova developers shall wait for the next, corrected update.Homer
Had exactly the same issue. Downgraded "Android SDK Tools" 25.2.3 which fixed the issue. We should probably wait for update from Google/Android team.Palstave
THANKS! Your answer worked perfectly. We'll have to wait for an update on this bug. You saved my work :DLagas
Thanks, this solved the problem, found similar workaround here forum.ionicframework.com/t/…Unyoke
Replacing only the tools folder did the trick for me. Did not have to remove and add the platform.Irreformable
I did the same thing and worked. But when I updated tools from Android SDK manager, the same problem resurfaced - 'ANDROID_HOME' missing and after setting that I got error message - 'gradle file missing' while building the App via PhoneGap CLI.Fennell
Very useful, for Mac you can do the same except for downloading tools for Windows, you download from Mac on this address: dl.google.com/android/repository/tools_r25.2.3-macosx.zipIlluminate
The original file can be accessed directly here: dl.google.com/android/repository/…Ballonet
Tools for linux: dl.google.com/android/repository/tools_r25.2.3-linux.zipJackscrew
I am still get similar after manually downloading sdk tools .please any one me.getting Error: Could not find an installed version of Gradle either in Android Studio"Android SDK Tools : 25.2.5,Cordova Platforms : android 6.2.3 ,Ionic Framework : ionic1 1.3.2.please any one help me i open new question.here (#45771257)Janson
downloaded afterroot.wordpress.com/2016/01/01/… and replaced from <ANDROID_HOME>/tools to 25.2.5 and tried to install plugin again and worked fineMitten
For me, removing and then adding the android plugin did the trick (didn't have to do anything else).Winebibber
Thank you so much it's worked for me while replacing tools_r25.2.3.Carma
tnx, i was searching all dayChita
D
258

Edit 3:

Cordova Android 6.2.2 has been released and it's fully compatible with SDK tools 26.0.x and 25.3.1. Use this version:

cordova platform update [email protected]

or

cordova platform rm android
cordova platform add [email protected]

Edit 2:

There has been another Android SDK tools release (26.0.x) that is not fully compatible with cordova-android 6.2.1.

Edit: Cordova Android 6.2.1 has been released and it's now compatible with latest Android SDK.

You can update your current incompatible android platform with cordova platform update [email protected]

Or you can remove the existing platform and add the new one (will delete any manual change you did inside yourProject/platforms/android/ folder)

cordova platform rm android cordova platform add [email protected]

You have to specify the version because current CLI installs 6.1.x by default.

Old answer:

Sadly Android SDK tools 25.3.1 broke cordova-android 6.1.x

For those who don't want to downgrade the SDK tools, you can install cordova-android from github url as most of the problems are already fixed on master branch.

cordova platform add https://github.com/apache/cordova-android

Depalma answered 14/3, 2017 at 22:32 Comment(32)
Will be correct answer once cordova-android 6.2.0 is released, at the moment is in development and not everybody is willing to use it before it's released.Depalma
Where can I keep track of this issue and cordova-android releases?Unshroud
I also got the following error when running cordova run android --list. Is this related? An unexpected error has occured while running list-emulator-images with code 2: Error: /Users/Shawn/Desktop/FRCCApp/platforms/android/cor dova/lib/list-emulator-images: Command failed with exit code 2Unshroud
Yes, that error is also related. Most of the problems are linked in this issue issues.apache.org/jira/browse/CB-12554. Once it's released, it will be announced on the blog cordova.apache.org/blog and on twitter.Depalma
The release is now up on the npm repositories, although it doesn't seem to be being used automatically yet. cordova platform add [email protected] works, though.Botulinus
Yeah, it requires a CLI release to be used as default, that will take longerDepalma
Removing platform and adding it again just worked for me.Rochkind
I'm using Android Tools 26.0.2 with [email protected] but I still have the issue 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 StudioIntermixture
@MichaelBurger that's a different issue, you now need Gradle installed in your system and set it in your path.Depalma
Using cordova platform add https://github.com/apache/cordova-android solved it for me. Thanks.Amharic
@Amharic cordova platform add [email protected] is safe to use now, you don't need to add github version and it might be unstable, better use 6.2.3 as is the latest released oneDepalma
I'm on Cordova 7.0.1 and I'm getting the error: Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK. Any advice?Aceae
@EthanKeller but did you had the android platform added previously? If that's the case, remove it cordova platform rm android re add it cordova platform add androidDepalma
Removed, added 6.2.2, got error cordovaProject.projectConfig.getFileResources is not a functionBallonet
You also need Cordova CLI 7.0.1Depalma
just removing and adding the platform or updating the android platfrom fixes this issue. Confirmed after 4 hours of frustration. Thanks.Versicular
What must we write in config.xml in case using 7.0.1 ? Which SDK Version?Kibler
@nottinhill I don't understand the question, I didn't mention anything about the config.xml on my answerDepalma
Why not just android@latest?Beane
@Beane by the time I answered, it wasn't even released, I've been editing with the version numbers that were fixing issues related to the Google changes. Now you can use android@latest without problems.Depalma
I m using latest version of cordova, [email protected] is default. The error still existsBerkeleianism
@Berkeleianism did you remove and re add the platform?Depalma
yes, tried each and very solution mentioned on this post, finally i had to install gradle from ubuntu repoBerkeleianism
@sziraqui, ah, yeah, since cordova-android 6.2.1 it requires Android Studio or Gradle to be installed on the user's system to workDepalma
I have Android Studio installed and working, I work on native android, I m trying cordova. Why can't cordova detect gradle that comes with Android Studio?Berkeleianism
It's supposed to detect it, it works in macOS, probably nobody tested it on ubuntu, can you report it on issues.cordova.io?Depalma
ionic cordova platform add android@latest fixed my prob . Thanks for ansLatour
@LAnantaPrasad latest is 7.1.1, that should also work and it's newer, or at least 6.4.0 that is latest 6.x.xDepalma
Great fix! Recently upgrade to latest android studio and just needed to update cordova android to the above. Way to go!Damondamour
well, you could give cordova-android 8.0.0 a go as it's latest oneDepalma
Got me past there - now I get Could not determine java version from '13.0.2'.Lim
Cordova only supports java 8 at the momentDepalma
N
247

I just experienced the same problem.

It may be an occlusion in the instructions regarding how to install (or upgrade) Android Studio with all the SDK Tools which both you and I missed or possibly a bug created by a new release of Studio which does not follow the same file conventions as the older versions. I lean towards the latter since many of the SO posts on this topic seems to point to an ANDROID_PATH with a folder called android-sdk which does not appear in the latest (2.3.0.8) version.

There appears to be a workaround though, which I just got to work on my machine. Here's what I did:

  • Download tools_r25.2.3-windows.zip from Android Downloads.

  • Extracted zip on desktop

  • Replaced C:\Users\username\AppData\Local\Android\sdk\tools with extracted sub-folder tools/

  • In project folder:

    $ cordova platforms remove android
    $ cordova platforms add android

You may also need to force remove the node_modules in android. Hopefully this helps.

Nonperformance answered 7/3, 2017 at 2:32 Comment(14)
THX, I've been trapped in the same phenomenon, now recovered my environment by your remedy. I think it is the fault of Google, so cordova developers shall wait for the next, corrected update.Homer
Had exactly the same issue. Downgraded "Android SDK Tools" 25.2.3 which fixed the issue. We should probably wait for update from Google/Android team.Palstave
THANKS! Your answer worked perfectly. We'll have to wait for an update on this bug. You saved my work :DLagas
Thanks, this solved the problem, found similar workaround here forum.ionicframework.com/t/…Unyoke
Replacing only the tools folder did the trick for me. Did not have to remove and add the platform.Irreformable
I did the same thing and worked. But when I updated tools from Android SDK manager, the same problem resurfaced - 'ANDROID_HOME' missing and after setting that I got error message - 'gradle file missing' while building the App via PhoneGap CLI.Fennell
Very useful, for Mac you can do the same except for downloading tools for Windows, you download from Mac on this address: dl.google.com/android/repository/tools_r25.2.3-macosx.zipIlluminate
The original file can be accessed directly here: dl.google.com/android/repository/…Ballonet
Tools for linux: dl.google.com/android/repository/tools_r25.2.3-linux.zipJackscrew
I am still get similar after manually downloading sdk tools .please any one me.getting Error: Could not find an installed version of Gradle either in Android Studio"Android SDK Tools : 25.2.5,Cordova Platforms : android 6.2.3 ,Ionic Framework : ionic1 1.3.2.please any one help me i open new question.here (#45771257)Janson
downloaded afterroot.wordpress.com/2016/01/01/… and replaced from <ANDROID_HOME>/tools to 25.2.5 and tried to install plugin again and worked fineMitten
For me, removing and then adding the android plugin did the trick (didn't have to do anything else).Winebibber
Thank you so much it's worked for me while replacing tools_r25.2.3.Carma
tnx, i was searching all dayChita
T
57

(Basically what @user3464070 already said)

For Mac:

cd ~/Library/Android/sdk
# download latest tools
curl -O https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip
# overwrite existing tools folder without prompting
unzip -o tools_r25.2.3-macosx.zip
# clean up
rm tools_r25.2.3-macosx.zip
Taejon answered 13/3, 2017 at 20:9 Comment(4)
First line could be cd $ANDROID_HOME for simplicity?Mantissa
@Mantissa could be but $ANDROID_HOME is not defined on my machine.Taejon
thx a lot. your commands + using [email protected] work like a charm on mac!Proudlove
Perfect answer! Seems like the easiest solution! Thanks :)Paluas
K
45
  1. If you have android studio installed within your system, then copy the templates folder from C:\Program Files\Android\Android Studio\plugins\android\lib\templates
  2. Paste it in the folder C:\Users\<user-name>\AppData\Local\Android\sdk\tools
  3. Run the command: ionic build android

All necessary jar files will be downloaded and apk file for the application will be generated.

Note: Set environment variables to C:\Users\<user-name>\AppData\Local\Android\sdk\tools. Also set user-name to your current username.

Kaleighkalends answered 21/4, 2017 at 16:42 Comment(4)
Simple and easy solution!Aspasia
This is an easy and economical solution for those who have Android Studio.Sluff
it actually worked for me.. when other solutions didn't. Too bad it seems mostly to depend on cordova/ionic/sdk/android studio versionsInquietude
As of 2018 and working with 2 different versions of Cordova, I can vouch for this solution as one that works and does not need additional downloads.Therefrom
T
25

For Linux there is even a bit better solution.

Navigate to https://developer.android.com/studio/index.html#downloads

and download the command line tools zip file (bottom of the page) for linux. Extract them to your ..../Android/Sdk/ folder so you overrwrite/extend your tools folder. Now everything works fine.

Terrorist answered 9/3, 2017 at 18:10 Comment(4)
Yeah, R J answered the Windows workaround for the problem, and your answer is the Linux solution. Useful for someone who doesn't know how to solve Windows' C:\Users\username\AppData\Local\Android\sdk\tools to Ubuntu's /home/user/Android/SdkLagas
@Lagas The answers are basically the same. Download tools, extract the zip folder and save the extracted content to your idk's tools folder. How difficult can it be to understand? I'm using a Mac and will save to ~/Library/Android/sdk/tools Need I steal someone's up votes for explaining the same thing in different words?Kamasutra
@Anon Yep, can't deny his answer was pretty much the same explanation with different words. But i can see some value in it for struggling beginners like me lolLagas
previous versions are not available anymore in developer.android.comJackscrew
S
20

For anyone who is still having this issue, this worked for me:

    cordova platform update android@latest

then build and it will automatically download the newest gradle version and should work

Sophia answered 1/8, 2017 at 20:4 Comment(2)
+1 This works as @ August 2017 and updates you to [email protected]. Older answers may or may not work or be correct any more. This situation keeps changing and is directly caused by Android SDK 25.3.1 dropping support for the android binary, as described here: cordova.apache.org/announcements/2017/04/05/…Aprilette
Still working as at Mar 2018. I don't create new cordova projects often, this is the first since my previous comment. It had the same could not find gradle wrapper error. I had to look up the solution on SO again. This is a per project fix, must be applied to every new cordova project you create. Would upvote twice if I could, this is the 2nd time this answer has saved me now.Aprilette
E
12

There's no need to downgrade Android Tools. On Windows, Gradle moved from:

C:\Users\you_username\AppData\Local\Android\sdk\tools

to:

C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle\wrapper

So you just need to adjust your path so that it points to the right folder.

Eggshell answered 20/3, 2017 at 15:29 Comment(3)
I did the opposite, moving the wrapper to my AppData and it works fine ! Thanks ^_^Embrasure
A new version of Cordova has been published recenly (five days ago) to solve this problemEggshell
Copy the content of the wrapper folder from this path C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle\wrapper to C:/Android/Sdk/tools/templates/gradle/wrapperGospodin
S
8

if you have this error when you ionic run android --device

## codova - android update 
npm install -g cordova
cordova platform update android
Sukin answered 23/5, 2017 at 22:41 Comment(0)
T
6

Just copied everything from typical Android Studio installation. From: D:\sw\dev\android\studio\plugins\android\lib\templates

(the whole templates directory)

To:

D:\sw\dev\android\sdk\tools

Tested with ionic build android

Tempa answered 2/5, 2017 at 22:54 Comment(1)
This was the solution in my case. After this solution, you might get the license message. See #40383823Velma
O
6

This problem occurs when you dont have the gradle wrapper into your SDK tools.

Like the previous responses said, you can update to last cordova-android version (it works), but if you want to keep working with [email protected] and [email protected], just copy the folder from android studio ex.;

cd /Applications/Android\ Studio.app/Contents/plugins/android/lib/
cp -r templates/ $ANDROID_HOME/tools/templates
chmod +x $ANDROID_HOME/tools/templates/gradle/wrapper/gradlew

In my case, I am using the cordova-plugin-fcm and it was tested with old version of cordova-android, so I can not use [email protected] (not yet).

Olgaolguin answered 5/11, 2017 at 15:20 Comment(0)
S
4

For Linux just make a symlink, like this:

ln -s /android/android-studio/plugins/android/lib/templates /android/sdk/tools/templates
Sesquipedalian answered 19/4, 2017 at 15:28 Comment(2)
Didn't test the symlink solution, but on my system /opt/android-studio/plugins/android/lib/templates/gradle/wrapper/gradlew has no execute permission. Make sure to chmod it before trying.Jackscrew
I don't have template/ folder under sdk/tools.Chaw
B
4

On linux (Ubuntu in my case) just install gradle:

sudo apt-get install gradle

Edit: It seems as though ubuntu repo only has gradle 2.10, for newer versions: https://www.vultr.com/docs/how-to-install-gradle-on-ubuntu-16-10

Behre answered 4/9, 2017 at 9:0 Comment(1)
None of the above solutions worked for me. I am using latest ver of cordova 7.0.1. Installing gradle from ubuntu repo solved the issue. Its 2017 and still cordova doesn't know to use Android studio's builtin gradleBerkeleianism
R
3

This solved my problem.

I just downloaded https://dl.google.com/android/repository/tools_r25.2.5-macosx.zip214 and overwrite the tools folder at ~/Library/Android/sdk/tools

Rittenhouse answered 29/5, 2017 at 12:38 Comment(0)
T
2

Just recently, I also encountered similar problem, and after I did this, it works:

I edited the file in /etc/profile

sudo nano /etc/profile

export JAVA_HOME=/home/abdul/java/jdk1.8.0_131
export PATH=$PATH:$JAVA_HOME/bin

export ANDROID_HOME=/home/abdul/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

export GRADLE_ANDROID_HOME=/home/abdul/android-studio/gradle
export PATH=$PATH:$GRADLE_ANDROID_HOME/gradle-3.2/bin
export PATH=$PATH:$GRADLE_ANDROID_HOME/m2repository

Other info (just in case):

Not quite sure about m2repository part, in the first try it pass the grandle but there is another error (gradlew-command-failed-with-exit-code-

  1. I check if in android studio the repository is active, and it's not active, I try to activate it, and when I try it again (Cordova build Android), it download a few other file, maybe from the repository? And then when I delete the path, it still works. (also thanks to Marcin Orlowski sample so then I can understand about export path better).

I use:

  • Linux Mint Serena
  • node : v6.10.3
  • npm : 3.10.10
  • Cordova : 7.0.0
  • Android Studio : 2.3.1
  • Android SDK platform-tools : 25.0.5
  • Android SDK tools : 26.0.2

Hope it can help anyone who might have the same problem like mine and need this too.

Thanks

Trenatrenail answered 5/5, 2017 at 23:52 Comment(0)
J
1

No need to update sdk. Try to install it manually. Follow instructions in this link

https://gradle.org/install

Jointly answered 29/4, 2017 at 6:17 Comment(0)
H
1

None of the solutions worked for me as of today. My situation was that I got my Android studio updated. The most popular thing to replace the tools folder with the latest one wouldn't work for me. Infact is not required in some cases.

npm update -g cordova did the trick for me.

Then I removed the platform and added it again.

ionic platform remove android

ionic platform add android

This works for me in Ionic. I am surecordova platform remove/add android will do the same stuff. Not tested though.

Working again !

Hanselka answered 17/5, 2017 at 8:40 Comment(0)
B
1

After trying everything here twice in different order, I reinstalled everything and before doing cordova platform add android I went to templates/gradle and ran gradlew.bat. After this completed, I was able to add the android platform without any problem.

Ballonet answered 26/5, 2017 at 17:38 Comment(0)
S
0

This solved it for me:

cordova platform update [email protected]
Scission answered 21/3, 2017 at 16:7 Comment(0)
R
-1

Run:

cordova platform update [email protected]

And make sure that Android Studio and Android Studio environment variable refrence to same location.

I fix this by copying Android Studio from:

D:\Program Files\Android

to

C:\Program Files\Android
Rumrunner answered 8/4, 2017 at 0:44 Comment(0)
A
-1

After cordova upgrade to 7.0.x, the gradle path has been changed as discussed above. To get it working before official fix comes out, just manually install the gradle and set it in your Environment.

  1. Go https://gradle.org/install download the Binary packages
  2. Unzip it,remember the path, eg., My one at: E:\Gradle
  3. Set the environment variables, like on Windows add E:\Gradle\bin

That's it.

Airman answered 18/5, 2017 at 6:5 Comment(0)
M
-1

After experienced the same issue, just rename the package name in config.xml, attribute id with a name without "-" inside...

i.e.

com.web-projet.appname

renamed into :

com.webprojet.appname

and all was correct...

If it helps.

Mayworm answered 21/5, 2017 at 19:2 Comment(0)
B
-1

Installing cordova version 5.0 helps me:

npm install -g [email protected]
Berar answered 25/5, 2017 at 10:58 Comment(0)
M
-1

I am using Ubuntu 16.04 and for me, it worked by just using two commands:-

ionic cordova platform rm android
ionic cordova platform add [email protected]
Margo answered 16/9, 2018 at 14:43 Comment(0)
I
-2

Easy and simple solution for MAC

My Issue was

cordova build android
ANDROID_HOME=/Users/jerilkuruvila/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home
Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: /Users/jerilkuruvila/Library/Android/sdk/tools/templates/gradle/wrapper

Solution

jerilkuruvila@Jerils-ENIAC tools $ cd templates
-bash: cd: mkdir: No such file or directory
jerilkuruvila@Jerils-ENIAC tools $ mkdir templates
jerilkuruvila@Jerils-ENIAC tools $ cp -rf gradle templates/
jerilkuruvila@Jerils-ENIAC tools $ chmod a+x templates/

cordova build android again working now !!!

Inobservance answered 20/4, 2017 at 2:18 Comment(1)
Do you explain this? Why happen?Bracteole

© 2022 - 2024 — McMap. All rights reserved.