Ionic Commands for building and Publishing Hybrid Mobile Apps

By | June 10, 2016

1. Desktop browser testing

Testing your app in a browser is as simple as running the serve command in your project’s root folder.

$ ionic serve

2. Simulator testing

You can also test right in the simulator using the cordova commands from the previous chapter. For example, to test in the iOS simulator, run:

$ ionic build ios
$ ionic emulate ios

Substitute ios with android for Android testing. If you want to get advanced, you can also open up the project file for a specific platform by opening the required XCode or Android Eclipse project in platforms/PLATFORM inside the root of your project. Then, you can build and test from inside the platform-specific IDE. Note: if you go this route, I recommend still working inside of the root www folder, and when you’ve made changes to this folder, run the command:

$ cordova prepare ios

Which will update the ios specific project with the code from the www folder. Note: this will overwrite any changes you’ve made to the platforms/ios/www and other platform-specific folders.

3. Testing as a native app

Since we are building a native (or “hybrid”) app, we can (and should!) test it as one. There are several ways to do this. If you are building for iOS, you’ll need to sign up for an Apple Developer account to test as a native app on an iPhone or iPad. Unfortunately, this costs $99 per year (don’t blame us!). Once you have an account and you have set up XCode with your certificates to enable device testing, you’ll want to open the XCode project from platforms/ios/ and do your testing from XCode.

Testing on Android is much easier and faster. To test on the device, simply plug it in, and run

$ ionic run android

If this doesn’t work, make sure you have USB debugging enabled on your device, as described on the Android developer site.

Publishing Ionic Apps

Android Publishing

To generate a release build for Android, we can use the following cordova cli command:

$ cordova build --release android

This will generate a release build based on the settings in your config.xml. Your Ionic app will have preset default values in this file, but if you need to customize how your app is built, you can edit this file to fit your preferences. Check out the config.xml file documentation for more information.

Next, we can find our unsigned APK file in platforms/android/build/outputs/apk. In our example, the file was platforms/android/build/outputs/apk/HelloWorld-release-unsigned.apk. Now, we need to sign the unsigned APK and run an alignment utility on it to optimize it and prepare it for the app store. If you already have a signing key, skip these steps and use that one instead.

Let’s generate our private key using the keytool command that comes with the JDK. If this tool isn’t found, refer to the installation guide:

$ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

You’ll first be prompted to create a password for the keystore. Then, answer the rest of the nice tools’s questions and when it’s all done, you should have a file called my-release-key.keystore created in the current directory.

Note: Make sure to save this file somewhere safe, if you lose it you won’t be able to submit updates to your app!

To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:

$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore HelloWorld-release-unsigned.apk alias_name

This signs the apk in place. Finally, we need to run the zip align tool to optimize the APK. The zipalign tool can be found in /path/to/Android/sdk/build-tools/VERSION/zipalign. For example, on OS X with Android Studio installed, zipalign is in ~/Library/Android/sdk/build-tools/VERSION/zipalign:

$ zipalign -v 4 HelloWorld-release-unsigned.apk HelloWorld.apk

Now we have our final release binary called HelloWorld.apk and we can release this on the Google Play Store for all the world to enjoy!

iOS Publishing.

1. Sign Up as a Developer
2. Create app in Itunes
3. Create Certificates
4. Open Cordova app in Xcode
5. Sign the App.

More about this is published in here.

Leave a Reply

Your email address will not be published. Required fields are marked *