Angular 2 Ionic 2 Build Android

Angular 2 ionic 2 build android is the process that allows us to create our apk file. The apk file can be installed on Android devices.

angular 2 ionic 2 android
angular 2 ionic 2 android

This is a step by step on how to build a release apk file. And then we can run this apk on our android device : )

Before we start open a terminal (command line) and navigate into you app folder (cd myappfolder)

Step 1 : we add the android platform


ionic platform add android

Step 2 : go to platforms folder and then to android folder


cd platforms/android

Step 3 : we generate a key.store file


keytool -genkey -v -keystore <strong>angular2ionic2.keystore</strong> -alias <strong>angular2ionic2</strong> -keyalg RSA -keysize 2048 -validity 10000

Once you finish the questions you will find a file like: angular2ionic2.keystore

You will enter a password during the generation of angular2ionic2.keystore you need to remember this password and keep your angular2ionic2.keystore in a safe place.

Step 4:  open the file build.gradle in the current directory platforms\android

We will tell gradle about the keystore.

Search the android section in this file it looks like :


android {

….

}

Then search the section (signingConfigs) under android {} and add the code :


signingConfigs {

release {
storeFile file("angular2ionic2.keystore")
storePassword 'YourPassword'
keyAlias 'angular2ionic2'
keyPassword 'YourPassword'
}

}

Step 5: run the build command

Back to your root folder and run this command.


ionic build android --release

Wait until the build is successfully accomplished, it will generate this file :

android-release-unsigned.apk

And then we sign it.

Step 5 : sign the apk file.


jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <strong>angular2ionic2.keystore</strong> <strong>android-release-unsigned.apk</strong> angular2ionic2

 

Hint: for security reasons don’t store the file angular2ionic2.keystore (YourApp.keystore) under work project.

The app is ready to be installed under your Android devices.