28 Oct 2014

Sample PhoneGap App with Intellij Idea

These are my notes how to get a quick PhoneGap / Cordova sample app running on Uubntu with Intellij Idea.

I'm going to use the sample PhoneGap, jQuery Mobile, Backbone.js app called gthockey-phonegap and posted on GitHub.

Install Cordova & Setup Project

You must already have the node.js packager, npm, installed. Execute these commands to setup the Cordova project

npm install -g cordova

Intellij Setup

Start Intellij and let's create the new project via File > New Project. The select Static web > PhoneGap/Cordova App and Next.

In the dialog box, enter gthockey as the project name and enter the directory where the project will be stored (I'll assume ~/gthockey) Set the executable to /usr/bin/cordova and click Finish.

Pull gthockey-phonegap.git from GitHub

Use the git command to pull the gthockey-phonegap app. This will create a new directory called gthockey-phonegap.

cd ~/gthockey
git clone https://github.com/msandt3/gthockey-phonegap.git

Move GTHockey, Build and Run

rm -rf www
mv gthockey-phonegap/www .
cordova platform build android
cordova emulate android

The emulator is very slow, let's enable developer mode on a nearby android device and try running it on the device. Plug the device in and execute the command:

cordova run android


Git is not required for this but I had problems with the Intellij import of a PhoneGap/Cordova project so before we do the import, I'm going to do a backup with Git.

git init
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL"
git config --list
git add *
git commit -m 'initial commit'

Intellij Run/Debug Configuration

Click Run > Edit Configurations and then hit the + key and choose PhoneGap/Cordova. In the dialog box change the Name to gthockey, the executable path to /usr/bin/cordova and the working directory to the gthockey directory. Click Ok to save the configuration.

The default setup runs the emulator, change the command field to run if you want it to run on your attached device (much quicker).