UPDATE: 21 May 2017
Ok, this was a really nasty issue and I felt compelled to write complete instructions to fix in the hope it saves others the hours I wasted on it. The following is a combination of googling, reading the accepted answer, and working things out from trial and error.
Before you do anything else.. make sure you close Docker if it is running. A symptom is that in Android Studio, the emulator load dialog just silently vanishes. If you ran from the app start command, your application is simply left waiting to connect to device (message issued).
Assuming you have done that and still not working, read on.
Optional (maybe): fyi only - Personally, I used SDK Man to install a matching version of Gradle on my machine.
Assume you have already got a working Android Studio emulator with Marshmallow or Nougat (or both).
In my case, I was then trying to get Cordova to work.
Depending on whether you wish to start over (recommended) then:
cordova platform rm android
cordova platform add android
First a download is needed. Download the following according to your OS:
https://dl.google.com/android/repository/tools_r25.2.3-windows.zip
https://dl.google.com/android/repository/tools_r25.2.5-linux.zip
(I was running on Mac, so downloaded:)
https://dl.google.com/android/repository/tools_r25.2.5-macosx.zip
Unzip it, and copy the templates
folder into /Users/arcseldon/Library/Android/sdk/tools
Explanation: See the logic inside module.exports.check_gradle
function, declared under platforms/android/cordova/check_reqs.js
to understand how it is trying to derive the path for the gradle wrapper. This co-erces it.
$ echo $ANDROID_HOME
/Users/arcseldon/Library/Android/sdk
I could see a tools
subdirectory, but no templates
folder inside that.
So copy the templates
folder from the downloaded and extracted zip, and paste it inside $ANDROID_HOME/tools
You should finish with a path hierarchy that includes:
/Users/arcseldon/Library/Android/sdk/tools/templates/gradle/wrapper
This now satisfies the path search from the script perspective.
Secondly, check your cordova application for platforms/android/build.gradle, and search for the gradleVersion
.
task wrapper(type: Wrapper) {
gradleVersion = '2.14.1'
}
For your version, download from URL as follows:
https://services.gradle.org/distributions/gradle-X.Y.Z-all.zip
replacing X, Y, Z as needed to match your version.
In my case,
https://services.gradle.org/distributions/gradle-2.14.1-all.zip
other examples:
https://services.gradle.org/distributions/gradle-3.3-all.zip
https://services.gradle.org/distributions/gradle-2.4-all.zip
Then, once downloaded, place on your local drive and reference with ENV. variable. eg. (changing to your version)
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=file:///Users/myusername/temp/gradle-2.14.1-all.zip
Explanation: If you run a search you'll find this environment variable is an optional override for this env. variable.
See the variable assignment for check_gradle
, declared under platforms/android/cordova/lib/builders/GradleBuilder.js
Now just run:
cordova run android --verbose
All going well, everything should now "just work" for Android. In my case, iOS was out of the box - but I did use Xcode 8.2 instead of Xcode 8.3 for other reasons.