Cordova – Build Android

Last time in a Cordova – Intro we created a simple app that used the stock assets and ran it in our browser. Now let’s get the Android SDK so we can build and run it on our device or emulator.

Downloads

We will start by getting the Android SDK from google at developer.android.com. During installation it will check to see if you have the Java Development Kit installed. If you don’t it’s available from Oracle on the Java SE Downloads page.

Once you have those two things installed you will need to use the Android SDK Manager to get the tools and platform you want to build for installed. For the tools you will need to latest and for the platform Cordova currently supports up to API 22. This may take a while based on your internet connection so you might want to let Twitter or Facebook know that you are installing the Android SDK and tools to build with Cordova.

If You Build It, You Will Have an App

Once you have to tools run cordova build android from the root directory of you project. This will of course generate some feedback in the console.

The important part is where is says BUILD SUCCESSFUL and the location of your apk.

Run the App

Now that you can build an Android app with Cordova let’s run it on a device. If you have an Android device handy you can enable developer options in the settings and then enable USB debugging.

There are too many variations of Android for me to cover enable developer options but a quick GoogleBing should help you find the secret button combination. It usually is along the lines of go to your About Phone in the settings and tap the Build Number 7 times.

Now attach your phone to the computer with a USB cable and use the command cordova run android. This will rebuild the app and deploy it to your device.

Conclusion

Now with this basic knowledge we can start to do some fun stuff. Next time we will look at starting to modify the assets we use for the app and make it more our own. Think I missed something? Let me know by leaving a comment below or send an email to me at brett@wipdeveloper.com.