Step by step guide create apk for your ionic framework project

Programmer Gamer Classic White Coffee Mug

I just learn to use ionic framework and I like it since I can use my knowledge in html and css a bit. The process also push me to learn about angular js. As the process getting fun each day I got litttle problem with create apk process (part of publishing). Specially in sign step. I try to recreate it by make simple ‘blank’ project.

Here’s my environment :

$ ionic info

Your system information:

Cordova CLI: 5.3.1
Gulp version:  CLI version 3.9.0
Gulp local:
Ionic CLI Version: 1.6.5
Ionic App Lib Version: 0.3.9
OS: Distributor ID:    Peppermint Description:    Peppermint Five
Node Version: v4.0.0

Create the project

$ ionic start test blank

$ cd test/

$ ionic platform add android

Start process build apk

$ cordova plugin rm cordova-plugin-console

$ cordova build –release android

…………….

……………………

……………………………

BUILD SUCCESSFUL

Total time: 13.138 secs
Built the following apk(s):
/home/alamsyah/test/platforms/android/build/outputs/apk/android-release-unsigned.apk

Generate Private Key

I use this convention :

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

$ keytool -genkey -v -keystore test.keystore -alias testkey -keyalg RSA -keysize 2048 -validity 10000
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]:  alamsyah rasyid
What is the name of your organizational unit?
[Unknown]:  digitalfusi
What is the name of your organization?
[Unknown]:  digitalfusi
What is the name of your City or Locality?
[Unknown]:  palembang
What is the name of your State or Province?
[Unknown]:  sumsel
What is the two-letter country code for this unit?
[Unknown]:  id
Is CN=alamsyah rasyid, OU=digitalfusi, O=digitalfusi, L=palembang, ST=sumsel, C=id correct?
[no]:  yes

Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days
for: CN=alamsyah rasyid, OU=digitalfusi, O=digitalfusi, L=palembang, ST=sumsel, C=id
Enter key password for <testkey>
(RETURN if same as keystore password):
[Storing test.keystore]

Sign apk file

1st error :

$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore test.keystore android-release-unsigned.apk test
Enter Passphrase for keystore:
jarsigner: Certificate chain not found for: test.  test must reference a valid KeyStore key entry containing a private key and corresponding public key certificate chain.

note : I don’t use absolute path for this command.

2nd error :

$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /home/alamsyah/test/test.keystore android-release-unsigned.apk testkey
Enter Passphrase for keystore:
jarsigner: unable to open jar file: android-release-unsigned.apk

note : I type the command not in the same location of .apk file

$ cd platforms/android/build/outputs/apk/

retype the command

$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /home/alamsyah/test/test.keystore android-release-unsigned.apk testkey
Enter Passphrase for keystore:
adding: META-INF/MANIFEST.MF
adding: META-INF/TESTKEY.SF
adding: META-INF/TESTKEY.RSA
signing: AndroidManifest.xml
signing: assets/www/cordova-js-src/android/nativeapiprovider.js
signing: assets/www/cordova-js-src/android/promptbasednativeapi.js
signing: assets/www/cordova-js-src/exec.js
signing: assets/www/cordova-js-src/platform.js
signing: assets/www/cordova-js-src/plugin/android/app.js
signing: assets/www/cordova.js
signing: assets/www/cordova_plugins.js
signing: assets/www/css/style.css
signing: assets/www/img/ionic.png
signing: assets/www/index.html
signing: assets/www/js/app.js
………………………………………………

………………………………………………………

signing: classes.dex
jar signed.

Warning:
No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate’s expiration date (2043-02-17) or after any future revocation date.

Optimize apk with zipalign

zipalign is part of jdk. In my case I already install it in /opt

$ pwd
/opt/android-sdk/build-tools/23.0.1
[email protected] /opt/android-sdk/build-tools/23.0.1 $ ls
aapt  arm-linux-androideabi-ld  dexdump  i686-linux-android-ld  jill.jar  llvm-rs-cc      mainDexClasses.rules     NOTICE.txt    runtime.properties  split-select
aidl  bcc_compat                dx       jack.jar               lib       mainDexClasses  mipsel-linux-android-ld  renderscript  source.properties   zipalign

So the correct command is :

$ /opt/android-sdk/build-tools/23.0.1/zipalign -v 4 android-release-unsigned.apk  test.apk
Verifying alignment of test.apk (4)…
50 META-INF/MANIFEST.MF (OK – compressed)
3297 META-INF/TESTKEY.SF (OK – compressed)
6633 META-INF/TESTKEY.RSA (OK – compressed)
7806 AndroidManifest.xml (OK – compressed)
8974 assets/www/cordova-js-src/android/nativeapiprovider.js (OK – compressed)
9752 assets/www/cordova-js-src/android/promptbasednativeapi.js (OK – compressed)
……………..

……………………

………………………..

2295604 res/drawable-xhdpi-v4/icon.png (OK)
2302852 res/drawable-xxhdpi-v4/icon.png (OK)
2314932 res/drawable-xxxhdpi-v4/icon.png (OK)
2331845 res/xml/config.xml (OK – compressed)
2333704 resources.arsc (OK)
2337101 classes.dex (OK – compressed)
Verification succesful.

That is good sign that apk successfully optimize and ready for google play 🙂

ls -l | grep apk
-rw-rw-r– 1 alamsyah alamsyah 2402681 Okt  2 16:46 android-release-unsigned.apk
-rw-rw-r– 1 alamsyah alamsyah 2402707 Okt  2 16:50 test.apk

Trying Eclipse on Ubuntu 13.04

I want to try Eclipse on my Ubuntu 13.04 . Installation process is quite straight perhaps useful for me in future use.

Checking Java

I already install Java before, check it first :

$ java -version

java version “1.7.0_25”
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
OpenJDK Server VM (build 23.7-b01, mixed mode)

Get nearest mirror from Eclipse website

As I’m from Indonesia I got mirror from University of Indonesia.

$ wget -c http://kambing.ui.ac.id/eclipse/technology/epp/downloads/release/kepler/SR1/eclipse-standard-kepler-SR1-linux-gtk.tar.gz

Checking md5 sum against :

bd98e1ac83cbc95909a3c856d3ced8a6  eclipse-standard-kepler-SR1-linux-gtk.tar.gz

$ md5sum eclipse-standard-kepler-SR1-linux-gtk.tar.gz
bd98e1ac83cbc95909a3c856d3ced8a6  eclipse-standard-kepler-SR1-linux-gtk.tar.gz

Good packet.

$ tar xvzf eclipse-standard-kepler-SR1-linux-gtk.tar.gz

$ sudo ln -s /home/alamsyah/eclipse/eclipse /usr/bin/eclipse
[sudo] password for alamsyah:
$

Launcher

$ sudo nano /usr/share/applications/eclipse.desktop

[Desktop Entry]
Version=4.3.1
Name=Eclipse
Comment=IDE for all seasons
Exec=env UBUNTU_MENUPROXY=0 /home/alamsyah/elipse/eclipse
Icon=/home/alamsyah/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=Utility;Application;Development;IDE

Done.

Add ADT Plugin

Start eclipse by typing : eclipse . Click Help and Install New Software.

Click Add button and enter :

Name : ADT

Url : https://dl-ssl.google.com/android/eclipse/

Next.

install_devel_android_eclipse

Click Next.

addroid_eclipse2

Accept Terms.

android_eclipse3

Choose ‘Always run in background’.

android_eclipse4

 

Installing Android SDK on Ubuntu Desktop 13.04

I want to learn about Android application and heard about phonegap. Android SDK is a must have before proceed to next step. Here my documentation for install android SDK on my Ubuntu Desktop 13.04 :

Get latest SDK Tools, minimalist is better. I pick SDK Tools only.

After get the link via firefox I decide to use wget :

$ wget -c http://dl.google.com/android/android-sdk_r22.3-linux.tgz
$ mv android-sdk_r22.3-linux.tgz /home/alamsyah/
$ cd /home/alamsyah/
$ tar xvzf android-sdk_r22.3-linux.tgz

update path ::

$ export PATH="$HOME/android-sdk-linux/tools:$HOME/android-sdk-linux/platforms:$PATH"

$ echo $PATH

/home/alamsyah/android-sdk-linux/tools:/home/alamsyah/android-sdk-linux/platforms:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

install jdk and  ant

$ sudo apt-get install openjdk-6-jdk ant

Selection_002

Click Install 9 Packages button to continue and get rid of “missing platform tools” error message.

Selection_003

After install remaining packages then the path need to adjust :

PATH=“$HOME/android-sdk-linux/tools:$HOME/android-sdk-linux/platforms:$HOME/android-sdk-linux/platform-tools:$PATH”
Last one need to install related to Android SDK is : android debug bridge
$ sudo apt-get install android-tools-adb

Enough 🙂