HTML5 Zone is brought to you in partnership with:

I'm a Worldwide Developer Evangelist for Adobe. My job basically entails me traveling the world and talking about the developer tools and technologies that Adobe has to offer or that we support. I'm also the author of Driving Technical Change. It's about convinving reluctant co-workers to adopt new tools and techniques. Terrence is a DZone MVB and is not an employee of DZone and has posted 40 posts at DZone. You can read more from them at their website. View Full User Profile

One Click PhoneGap Build to Android Device Script

  • submit to reddit

I've been fooling around with PhoneGap Build, and I really love it. I love that I don't need to fire up Eclipse or XCode to start fooling around with an app. All I need is a text editor and a browser. What I especially love is the ability to integrate a github repository to the whole process. It makes following proper development practice, while living in the cloud, very easy.

But I've been spoiled for the last year or so. Being able to immediately preview on a connected device has ruined me for the command line, multi-step, manual crap. So at least on Android I've fixed it for myself by building a nice shell script that takes advantage of PhoneGap Build's Web APIs to create a one-step build. 

What's involved:

  • Commit all uncommitted files to git repository
  • Push git repository to github
  • Tell PhoneGap Build to poll github for changes
  • Poll PhoneGap Build until Android apps have been rebuilt
  • Download App
  • Use ADB to install onto attached device.

So I wrote a little shell script to do it all for me. I hope it helps someone else who is struggling with the same workflow issue. The script is below.

One click build for PhoneGap Build to Android

#! /bin/sh 

project="[phonegap projectnumber]";
username="[phonegap username]";
password="[phonegap password]";
appPath="[path to www folder]"; 
projectPath="[path where you want the apk file]";


##commit changes
echo "Forcing changes to github";
cd $appPath
null=$(git commit -m "auto commit as part of script");
null=$(git push origin master);
echo "Done";

cd $projectPath

##Request Phonegap data
echo "Requesting Project Data.";
package=$(curl -s -u $creds  $APIcall | grep -Po '"package":.*?[^\\],');
title=$(curl -s -u $creds  $APIcall | grep -Po '"title":.*?[^\\],');
title=$(echo $title|sed 's/,//g');
title=$(echo $title|sed 's/"//g');
package=$(echo $package|sed 's/,//g');
package=$(echo $package|sed 's/"//g');
echo "Done. ";

##Request Rebuild
echo "Requesting Rebuild.";
request=$(curl -s -u $creds -X PUT -d 'data={"pull":"true"}' $APIcall);
echo "Done. ";

echo "\nWaiting for rebuild to be done.";
while [$donecheck -eq ""]
	echo ".";
	sleep 10;
	donecheck=$(curl -s -u $creds  $APIcall | grep -Po '"android":"complete"');	
echo "Done. Now downloading.\n";

##Download File
download=$(curl -L -s -u $creds -o $title-debug.apk $FILEPATH/$project/download/android);

##Install on Device
~/Downloads/android-sdk/platform-tools/adb uninstall $package
~/Downloads/android-sdk/platform-tools/adb install -r ./$title-debug.apk



Published at DZone with permission of Terrence Ryan, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Robert Craft replied on Thu, 2012/01/26 - 5:53am

Does this rebuild for every platform or only android on the side?

Java Collection

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.