It’s not the first time that I played with PhoneGap, but I haven’t done in quite some time. But I always liked the idea of creating a platform independent application. And if that application can be tested directly in the web browser, even better.
So it’s clear why I like the idea of PhoneGap right from the start. Now, let’s set it up.
To develop a Phonegap application you don’t need to many things. The best thing will be to install nodejs and then phonegap:
npm install -g phonegap.
Then you can create a sample application with
phonegap create my-app, command which will create all the necessary files and subfolders under
Now it comes the testing part and for this you need to install PhoneGap Desktop. As I said, it’s nice that you can test your app directly in your browser by visiting the link displayed at the bottom of Phonegap Desktop window, e.g. http://192.168.0.1:3000 (hint: it doesn’t work with localhost or 127.0.0.1). And if you install PhoneGap Developer App you can easily test on your mobile too without the hassle of installing the application itself every time you make a change – changes will be automatically deployed (reloaded).
When you’re done it comes the fun part – actually building the application. Let’s do this for Android.
First you need to install JDK (I tested with version 8) and Android Studio.
And then you need to setup some enviroment variables
- JAVA_HOME – this must be set to the folder where your JDK, not JRE, is installed.
- ANDROID_HOME – this must be set to the folder where your Android environment is installed.
- add to PATH the following
%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\binin Windows or
If the above are not correctly set or the PATH is invalid (like it has an extra quote(“) or semicolon(;)) you can run into errors like
Error: Failed to run "java -version", make sure that you have a JDK installed. You can get it from: http://www.oracle.com/technetwork/java/javase/downloads. Your JAVA_HOME is invalid: /usr/lib64/jvm/java-1.8.0-openjdk-1.8.0
Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
I also had to run
phonegap platforms remove android phonegap platforms add firstname.lastname@example.org
By default I had installed Android 5.1.1, but I was getting the error
Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable. You can check what platforms you have installed by running the command
phonegap platforms list.
Make sure that you have all the Android tools and SDKs installed by running
android on the command line and select all the ones not installed and install them.
Finally, you can build the application by running the following command in your project folder:
phonegap build android
and if everything goes well you’ll find your apk at