Building a PhoneGap project with plugins in Ubuntu

Okay, ladies and gentlemen, today I’m working on the proof of concept (PoC) of a mobile application that has to work with Bluetooth.

For this purpose I’ve chosen a PhoneGap framework which lets us build mobile application for all mobile platforms (Android, iOS, Windows Phone and some others). Strong side of PhoneGap is plugins – modules of native code for all mobile platforms which can be accessed from PhoneGap Javascript.

Normally for a simple project I’d choose Adobe Build to build the project for me. It can automatically build packages for all mobile platforms for you and even do more like publishing your project in corresponding app markets.

Unfortunately, I had issues building the project using Adobe Builder – it seems not to include plugins to the project. As right now I need only a package for Android, I decided not to strugle with Adobe and to build the .apk locally. For that go to the project directory and run the following:

$ phonegap build android

Build starting… and failing:

[phonegap] executing 'cordova platform add --save android'...
[phonegap] completed 'cordova platform add --save android'
[phonegap] executing 'cordova build android'...
Running command: /var/www/phonegap-bluetooth-poc/platforms/android/cordova/build

[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.]

ERROR building one of the platforms: Error: /var/www/phonegap-bluetooth-poc/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project

So, failed to find ‘android’ command in your ‘PATH’. To fix that we need an Android SDK; we’ll get it from Android website.

After installing Android SDK, let’s update environment variables. Add the following lines to the end of ~/.bashrc file (replace /home/minras/Android/Sdk/  with your path):

export ANDROID_HOME=/home/minras/Android/Sdk/
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

And finally run source ~/.bashrc to initialize those variables.

Now the build should succeed:

$ phonegap build android