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?

24 Answers 24

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

32
  • 7
    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.
    – Jules
    Commented Apr 1, 2017 at 4:43
  • 3
    @chrjs 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 one Commented May 9, 2017 at 10:42
  • 1
    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? Commented May 16, 2017 at 13:26
  • 1
    @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 android Commented May 16, 2017 at 14:19
  • 1
    Why not just android@latest?
    – Seanny123
    Commented Sep 4, 2017 at 1:54
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.

14
  • 1
    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. Commented Mar 7, 2017 at 9:38
  • 1
    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.
    – gregor
    Commented Mar 7, 2017 at 10:31
  • 3
    Replacing only the tools folder did the trick for me. Did not have to remove and add the platform.
    – vahissan
    Commented Mar 13, 2017 at 15:05
  • 16
    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.zip
    – O. Edholm
    Commented May 9, 2017 at 15:24
  • 14
    The original file can be accessed directly here: dl.google.com/android/repository/…
    – user736893
    Commented May 26, 2017 at 15:36
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
4
  • 1
    First line could be cd $ANDROID_HOME for simplicity?
    – toxaq
    Commented Mar 15, 2017 at 3:32
  • 1
    @toxaq could be but $ANDROID_HOME is not defined on my machine.
    – basecode
    Commented Mar 17, 2017 at 12:18
  • 2
    thx a lot. your commands + using [email protected] work like a charm on mac! Commented Apr 16, 2017 at 8:32
  • Perfect answer! Seems like the easiest solution! Thanks :)
    – Tomas
    Commented Oct 21, 2020 at 20:21
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.

4
  • 1
    Simple and easy solution! Commented Apr 23, 2017 at 19:28
  • 1
    This is an easy and economical solution for those who have Android Studio.
    – Johnson
    Commented May 13, 2017 at 7:31
  • 1
    it actually worked for me.. when other solutions didn't. Too bad it seems mostly to depend on cordova/ionic/sdk/android studio versions
    – Kaddath
    Commented Sep 14, 2017 at 14:55
  • 1
    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.
    – ravemir
    Commented Jul 23, 2018 at 9:39
24

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.

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/Sdk
    – rbenvenuto
    Commented Mar 9, 2017 at 19:52
  • @rbenvenuto 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? Commented Mar 10, 2017 at 12:37
  • 4
    @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 lol
    – rbenvenuto
    Commented Mar 10, 2017 at 17:08
  • previous versions are not available anymore in developer.android.com Commented Jul 20, 2017 at 1:36
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

2
  • 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/…
    – JK.
    Commented Aug 11, 2017 at 4:48
  • 1
    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.
    – JK.
    Commented Mar 30, 2018 at 7:21
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.

3
8

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

## codova - android update 
npm install -g cordova
cordova platform update android
0
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

1
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).

0
4

For Linux just make a symlink, like this:

ln -s /android/android-studio/plugins/android/lib/templates /android/sdk/tools/templates
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. Commented Jul 20, 2017 at 1:35
  • I don't have template/ folder under sdk/tools. Commented May 29, 2018 at 12:56
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

1
  • 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 gradle
    – sziraqui
    Commented Sep 24, 2017 at 15:59
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

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

1

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

https://gradle.org/install

0
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 !

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.

0

This solved it for me:

cordova platform update [email protected]
-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
-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.

-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.

-1

Installing cordova version 5.0 helps me:

npm install -g [email protected]
0
-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]
-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 !!!

1
  • 1
    Do you explain this? Why happen? Commented Apr 5, 2018 at 22:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.