Error: Could not find gradle wrapper within android sdk. Might need to update yo ur Android SDK

Ubuntu 14.04 fix

Hi there,
I was suffering from this issue and the things I tried from above didn’t help me.
I ended up creating the templates directory and copying the gradle wrapper from an existing project to fix it.

This was the error I got when running ionic cordova build android:

$ ionic cordova build android
> ionic-app-scripts build --target cordova --platform android
[20:22:51]  ionic-app-scripts 3.1.8

<build blah blah>

> cordova build android
ANDROID_HOME=/home/gust/Android/Sdk
JAVA_HOME=/opt/jdk
(node:10631) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): 
Could not find gradle wrapper within Android SDK. 
Might need to update your Android SDK.
Looked here: /home/gust/Android/Sdk/tools/templates/gradle/wrapper
$

This was happening even though I had recently installed Android Studio and the Android SDK (in Aug 2018).


Fix:
The error was pretty explicit:

Looked here: /home/gust/Android/Sdk/tools/templates/gradle/wrapper

So I tried to give Cordova what it wanted by creating the folder manually:

$ cd /home/gust/Android/Sdk/tools
$ mkdir -p templates/gradle/wrapper

And then I copied the wrapper from an existing project I had around that used gradle already. The contents of /home/gust/Android/Sdk/tools/templates/gradle/wrapper ended up looking like this:

.
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
└── gradlew.bat

And with that, Cordova was happy and gave me the apk I wanted:

$ ionic cordova build android

<build blah blah>

BUILD SUCCESSFUL

Total time: 11.874 secs
Built the following apk(s): 
	/home/gust/ionic/myIonicApp/platforms/android/build/outputs/apk/android-debug.apk
$

Info about Cordova itself:

$ cordova platform version android
Installed platforms:
  android 6.1.2
Available platforms: 
  amazon-fireos ~3.6.3 (deprecated)
  blackberry10 ~3.8.0
  browser ~4.1.0
  firefoxos ~3.6.3
  ubuntu ~4.3.4
  webos ~3.7.0
$ cordova --version
6.5.0

You can find more info about how to generate a gradle wrapper yourself in the Gradle Docs.

Cheers!
Gustavo.