Skip to content

Instantly share code, notes, and snippets.

@Costava
Last active March 2, 2017 05:28
Show Gist options
  • Save Costava/8a504b3fd32275ffb054c295b6bb0de2 to your computer and use it in GitHub Desktop.
Save Costava/8a504b3fd32275ffb054c295b6bb0de2 to your computer and use it in GitHub Desktop.
Build a Cordova project for Android and test it on a physical Android device.

Cordova with Android

Goal

Build a Cordova project for Android and test it on a physical Android device.

Platform: Windows 8.1

Problem

When I tried cordova build android, I got errors referencing %ANDROID_HOME%\tools\templates\gradlew... where %ANDROID_HOME% means the directory of my Android SDK (it has directories tools, platform-tools, etc.).

Solution

  1. In %ANDROID_HOME%\tools, make the directory templates. This did not already exist for me.
  2. Inside templates, run gradle wrapper. This will create the structure gradle\wrapper inside templates as well as other gradle related files.
  3. Inside %ANDROID_HOME%\tools\templates\gradle\wrapper, run gradle wrapper. Yes, that's correct. You are running the same command in a directory created by the last command.
  4. There should now exist %ANDROID_HOME%\tools\templates\gradle\wrapper\gradle\wrapper

At this point, cordova build android now worked for me (It did not work after steps 1-2 alone). I was able to build an .apk and run it on a physical Android device (Don't forget to turn on "USB debugging" in "Developer options". Your device should have an entry in the list from the command adb devices).

I do not know why this is needed or works. I do not know why the Android Platform Guide never covers it and never seems to cover anything that takes care of this situation (as of 2017 March 1).

It seems that some of the requirements from cordova requirements do not strictly need to be resolved. After getting it to work, running cordova requirements gives me:

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed 
Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
Gradle: installed
Error: Some of requirements check failed

If I missed or misread something in the Android Platform Guide, please let me know where I went wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment