Over a million developers have joined DZone.
Platinum Partner

One Click PhoneGap Build to Android Device Script

· Web Dev Zone

The Web Dev Zone is brought to you in partnership with Mendix.  Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.

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


Source: http://www.terrenceryan.com/blog/post.cfm/one-click-phonegap-build-to-android-device-script

The Web Dev Zone is brought to you in partnership with Mendix.  Learn more about The Essentials of Digital Innovation and how it needs to be at the heart of every organization.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}