Build a Cordova project for Android and test it on a physical Android device.
Platform: Windows 8.1
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.).
- In
%ANDROID_HOME%\tools
, make the directorytemplates
. This did not already exist for me. - Inside
templates
, rungradle wrapper
. This will create the structuregradle\wrapper
insidetemplates
as well as other gradle related files. - Inside
%ANDROID_HOME%\tools\templates\gradle\wrapper
, rungradle wrapper
. Yes, that's correct. You are running the same command in a directory created by the last command. - 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.