Now that you have your mobile application ready and running on Phonegap app, the next step would be to try them out on actual devices. To do that, for Android you would need to get your apk ready. This article will act as a step by step guide to accomplish exactly that on Ubuntu (I am using 14.04).
To Build The APK:
1. Add android platform specific codes, cd to the app directory and run:
1 |
$ phonegap platform add android |
You should see a “android” folder added in the app/platform directory.
2. Before you start building the apk you would need to get the setup right –
a) Install Java 8 on Ubuntu 14.04 :
1 2 3 |
$ sudo apt-add-repository ppa:webupd8team/java $ sudo apt-get update $ sudo apt-get install oracle-java8-installer |
b) Download the appropriate Android SDK (you need to get the one for Linux) from https://developer.android.com/studio/index.html. Unzip it in some folder.
c) Now to set JAVA_HOME, ANDROID_HOME and set PATH, open ~/.bashrc in your favorite editor and at the end of the file set the values –
1 2 3 4 |
JAVA_HOME=/usr/lib/jvm/java-8-oracle export JAVA_HOME export ANDROID_HOME=/home/whatever_name/Softwares/Android/Sdk export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools |
Now reboot.
3. Let’s proceed to build now, go to the app directory and run –
1 |
$ phonegap build android |
And now you should get the apk ready in [your-app-directory]/platforms/android/build/outputs/apk as android-debug.apk. This you can install in your device to test.
NOTE:- There might be a problem at this step if you are on a 64-bit distro and have not installed the 32-bits dependencies.
Nandini is a Web Developer and a blogger who loves tinkering with new technologies, frameworks and devices. When not in front of her computer she likes to travel, read and spend time gardening.