Skip to content

Building for Android and iOS

leob edited this page Nov 8, 2016 · 2 revisions

After you've tested the basics of your app using a browser (ionic serve), you will want to test it on a real device (Android or iOS) and eventually publish it to an app store. Below we explain how to do this.

Running on an Android device (development build)

To run the app on an Android device as a 'development build' ("APK file"):

  • make sure "USB debugging" is enabled in the Developer options of your Android device
  • use an USB cable to connect the Android device to your computer
  • run the following commands:
gulp build
ionic run android

(you can use the '-l' parameter to enable live-reload: ionic run android --device -l)

To view the device logs, run the command adb logcat. In most cases I'm only interested in the Javascript logging, so I would add a "grep" command for instance like this:

adb logcat|grep CONSOLE

Note: the ionic run android command produces an APK file (platforms/android/build/outputs/apk/android-armv7-release-unsigned.apk) which you can also distribute to your users/testers (for instance by email), they can simply download the APK from an email on their Android device and install it directly.

Creating an Android production build for distribution on Google Play

This is explained in detail in the Ionic docs (https://ionicframework.com/docs/guide/publishing.html) but here are the basic commands that you would use.

First you generate a signing key for your app, you need to do this only once. The command would be something like this (you would replace 'myapp' with the name of your app):

keytool -genkey -v -keystore myapp.keystore -alias myapp -keyalg RSA -keysize 2048 -validity 10000

Next, every time you need to create a production APK, execute the following commands:

gulp build
cordova build --release android
cp platforms/android/build/outputs/apk/android-armv7-release-unsigned.apk myapp-unsigned.apk

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore myapp.keystore myapp-unsigned.apk myapp

$ANDROID_HOME/build-tools/23.0.3/zipalign -v 4 myapp-unsigned.apk myapp-release.apk

The APK file (myapp-release.apk) can be distributed to your users/testers (for instance by email), they can simply download the APK from an email on their Android device and install it directly.

You can also install the APK by means of the command adb install myapp-release.apk (assuming that the device is connected to your computer by a USB cable).

Finally, the APK can of course be uploaded to Google Play for official distribution via the app store.

Note: if a 'debug APK' was already installed on a device, you will probably need to completely uninstall/remove the app before you can install the 'production APK'.

Running on an iOS device

Obviously this works only on a Mac, and also you need to have Xcode installed and configured (for details, see the excellent Ionic documentation: https://ionicframework.com/docs/guide/publishing.html).

Assuming these prerequisites are met, here is how to run the app on an iOS device:

  • use an USB cable to connect the iOS device to your computer
  • run the following commands, this generates an Xcode project:
gulp build
ionic run ios
  • start Xcode and open the generated Xcode project (something like platforms/ios/myapp.xcodeproj)
  • at the top of the Xcode screen, choose the "Scheme" (your app, not 'CordovaLib') and the "Target" (your device's name, not 'Generic iOS Device')
  • from the "Product" menu, choose "Run"

Creating a production iOS build for distribution on the Apple App Store

  • run the following commands, this generates an Xcode project:
gulp build
ionic build ios --release
  • start Xcode and open the generated Xcode project (something like platforms/ios/myapp.xcodeproj)
  • at the top of the Xcode screen, choose the "Scheme" (your app, not 'CordovaLib') and the "Target" (your device's name, not 'Generic iOS Device')
  • from the "Product" menu, choose "Archive"
  • from the "Window" menu, choose "Organizer"
  • Using the Organizer window, you can upload your archive (app) to the App Store
Clone this wiki locally