Tips For Building Cordova Apps On Android

I have a small Makefile that I use to automate signing, installing and running builds on an Android device.

It does the following:

  • Deletes the old apk (if exists). The -f flag will remove the old file without confirmation and will not display an error if the file does not exist:
rm -f yourfilename.apk
  • Runs the cordova build:
cordova build android --release
  • Signs the apk using the keystore, and passes the alias and password as cli arguments so no manual entry is required:
jarsigner -sigalg MD5withRSA -digestalg SHA1 -keystore certs/certname.keystore -storepass yourkeypass platforms/android/build/outputs/apk/android-release-unsigned.apk youralias

zipalign -v 4 platforms/android/build/outputs/apk/android-release-unsigned.apk yourfilename.apk
  • Installs the apk on the device. The -r flag overwrites the old apk so if the app is already installed you don't have to remove it manually each time:
adb install -r yourfilename.apk
  • Executes the cordova app so you don't have to look for the icon and tap it each time:
adb shell am start -n com.yourcompany.yourapp/com.yourcompany.yourapp.MainActivity
  • Prints out log events in the console and filters them to only see the events for the app you're currently running:
adb logcat | grep `adb shell ps | grep com.yourcompany.yourapp | cut -c10-15`

You can see the entire script in this gist. To use it, put it in your project's folder, update the variables on top and run make.

Follow me for updates on similar new posts I write or tweet about this post.