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

CordovaIonic FrameworkAndroid Gradle-Plugin

Cordova Problem Overview


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?

Cordova Solutions


Solution 1 - Cordova

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 android@6.2.2

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 add android@6.2.1```

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`

Solution 2 - Cordova

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.

Solution 3 - Cordova

(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

Solution 4 - Cordova

  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.

Solution 5 - Cordova

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.

Solution 6 - Cordova

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

Solution 7 - Cordova

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.

Solution 8 - Cordova

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

## codova - android update 
npm install -g cordova
cordova platform update android

Solution 9 - Cordova

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

Solution 10 - Cordova

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

Solution 11 - Cordova

For Linux just make a symlink, like this:

ln -s /android/android-studio/plugins/android/lib/templates /android/sdk/tools/templates

Solution 12 - Cordova

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

Solution 13 - Cordova

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

Solution 14 - Cordova

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

Solution 15 - Cordova

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

https://gradle.org/install

Solution 16 - Cordova

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 sure cordova platform remove/add android will do the same stuff. Not tested though.

Working again !

Solution 17 - Cordova

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.

Solution 18 - Cordova

This solved it for me:

cordova platform update android@6.1.2

Solution 19 - Cordova

Run:

cordova platform update android@6.1.2

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

Solution 20 - Cordova

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.

Solution 21 - Cordova

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.

Solution 22 - Cordova

Installing cordova version 5.0 helps me:

npm install -g cordova@5.0

Solution 23 - Cordova

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 android@6.3.0

Solution 24 - Cordova

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrbenvenutoView Question on Stackoverflow
Solution 1 - CordovajcesarmobileView Answer on Stackoverflow
Solution 2 - CordovaR JView Answer on Stackoverflow
Solution 3 - CordovabasecodeView Answer on Stackoverflow
Solution 4 - Cordovavinayb21View Answer on Stackoverflow
Solution 5 - Cordovauser3464070View Answer on Stackoverflow
Solution 6 - CordovaMansView Answer on Stackoverflow
Solution 7 - CordovaherveView Answer on Stackoverflow
Solution 8 - CordovaxsorView Answer on Stackoverflow
Solution 9 - CordovaAlexGeraView Answer on Stackoverflow
Solution 10 - CordovaBruno AgutoliView Answer on Stackoverflow
Solution 11 - CordovaMacView Answer on Stackoverflow
Solution 12 - CordovaMawcelView Answer on Stackoverflow
Solution 13 - CordovaDinesh VaitageView Answer on Stackoverflow
Solution 14 - CordovaAbdul MuhitView Answer on Stackoverflow
Solution 15 - CordovaArjun G PerambraView Answer on Stackoverflow
Solution 16 - CordovaHalfWebDevView Answer on Stackoverflow
Solution 17 - CordovaTHE JOATMONView Answer on Stackoverflow
Solution 18 - CordovaMirkoView Answer on Stackoverflow
Solution 19 - CordovaAvihai CohenView Answer on Stackoverflow
Solution 20 - CordovaPeter.WangView Answer on Stackoverflow
Solution 21 - CordovaJean-Luc AubertView Answer on Stackoverflow
Solution 22 - CordovafvukovicView Answer on Stackoverflow
Solution 23 - CordovaNirajView Answer on Stackoverflow
Solution 24 - CordovaJeril KuruvilaView Answer on Stackoverflow