37

I am trying to take build in an ionic2 application. I got this error while running ionic build android. The error log is

ANDROID_HOME=/home/varun/Android/Sdk
JAVA_HOME=/usr/lib/jvm/java-8-oracle
Error: Could not find gradle wrapper within Android SDK. Might need to    update your Android SDK.
Looked here: /home/varun/Android/Sdk/tools/templates/gradle/wrapper

I tried updating the sdk but it was found that the sdk version is latest.

When i looked at the Android/Sdk/tools folder there is no templates directory. I am running on ubuntu 16.04, with cordova version 6.5.0

5 Answers5

83

Edit:

There has been a newer release of Cordova Android that also fixes some problems with SDK tools 26.x.x

cordova platform update android@6.2.2

or

cordova platform rm android
cordova platform add android@6.2.2

Old answer

Google broke Cordova Android 6.1.x and some other frameworks with their latest sdk tools update.

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

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

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

jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
  • 1
    Didn't fix the issue for me. – dsp_099 Mar 21 '17 at 10:13
  • @dsp_099 did you remove android platform first? if you run `cordova platforms` what cordova-android version do you get? – jcesarmobile Mar 21 '17 at 11:40
  • I see "Installed platforms: android 6.1.2. See latest question on my profile for more info" – dsp_099 Mar 21 '17 at 11:44
  • 2
    then do a `cordova platform rm android` first and then `cordova platform add https://github.com/apache/cordova-android`, you should get 6.2.0-dev instead of 6.1.2 – jcesarmobile Mar 21 '17 at 11:47
  • Step in the right direction... That helped... [sort of](http://pastebin.com/enRYxNa9). See my [question here](http://stackoverflow.com/questions/42925597/android-studio-doesnt-install-sdks-what/42926194#42926194), seems to be the issue, might give you more intel. – dsp_099 Mar 21 '17 at 11:52
  • Thanks that fixed it for me after updating SDK tools to 25.3.1 – Pier Mar 27 '17 at 17:14
  • I get a warning: cmd: command failed with exit code 1 Can i get rid of it somehow? – Playdome.io Apr 06 '17 at 21:58
  • @Azarus which command? – jcesarmobile Apr 07 '17 at 06:58
  • 1
    When upgrading the android platform, this seems pretty messed up right now. :/ Spent like 4 hours just setting things up huh – Playdome.io Apr 07 '17 at 21:25
  • Thanks man, this worked fine for me – Herman Demsong Apr 22 '17 at 22:30
  • 1
    You little beauty. – Adam Apr 28 '17 at 12:42
  • Fantastic. Running `cordova platform update android` worked perfectly. It updated to 6.2.3. It must know to look for gradle in the new directory: C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle\wrapper – Lifz Aug 09 '17 at 20:08
  • How is 6.2.2 a newer release when OP has 6.5.0 ? The two solutions to this problem involve either downgrading Android SDK or Cordova, it doesn't seem like a very sustainable solution - you're going to have to upgrade eventually right? – ChickenFeet Aug 24 '17 at 04:01
  • @ChickenFeet No, you are confusing cordova-lib (or Cordova CLI) version with cordova-android version. Cordova CLI 6.5.0 had cordova-android 6.1.1, so, by the time I wrote this, he needed to upgrade the cordova-android version to 6.2.2. Now there is a new Cordova CLI version (7.0.1) that uses cordova-android 6.2.x as default. – jcesarmobile Aug 24 '17 at 07:17
  • cordova platform update android@6.2.2 fixed my issue. thanks bro..:) – Ananta Prasad Dec 05 '18 at 05:46
  • @LAnantaPrasad at this point you also have 6.4.0 or 7.1.4 available, that also have the problem fixed and are newer – jcesarmobile Dec 05 '18 at 11:48
  • @jcesarmobile thanks – Ananta Prasad Dec 14 '18 at 12:19
  • This is working for me thanks dude...... – Mahendren Mahisha May 02 '19 at 05:46
47

I resolved by this by replacing the tools folder in my Android SDK with an older version of the SDK tools (r25.2.3). Follow these steps to do the same:

  1. Navigate to https://developer.android.com/studio/index.html, click "Download Options", scroll down, and download the command line tools package for your platform, ensuring that you get a version in the r25.2.X series (not r25.3.X).
  2. Unzip this folder. You should end up with a tools directory.
  3. Navigate to your $ANDROID_HOME directory (~/Library/Android/sdk/ on OS X).
  4. Rename the pre-existing tools directory there to tools.bak (e.g., mv tools tools.bak)
  5. Move the tools directory you just downloaded into the SDK folder (e.g., mv ~/Downloads/tools/ .)

A new major version of the SDK tools was just released, which appears to be causing some issues with Ionic (see the press release here: http://tools.android.com/recent/androidsdktoolsrevision2530feb2017).

tobias.mcnulty
  • 1,621
  • 14
  • 15
5

This worked for me

cordova platform update android@6.1.2

Paranoid Android
  • 4,672
  • 11
  • 54
  • 73
4

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 ajust your path so that it points to the right folder.

herve
  • 525
  • 6
  • 17
1

I had same problem and I solved it with Carlos Delgado's answer.

  • Android Path must be set before all things below.
  • Download the latest command line tools (https://developer.android.com/studio/index.html -> very bottom part)
  • Unzip -> copy and paste "tools > templates" folder to your project folder (/Libraries/Android/sdk/tools/)
  • press option key to see Libraries folder in your Finder
Muhyun Kim
  • 23
  • 4