DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > One Click PhoneGap Build to Android Device Script

One Click PhoneGap Build to Android Device Script

Terrence Ryan user avatar by
Terrence Ryan
·
Dec. 10, 11 · Web Dev Zone · Interview
Like (1)
Save
Tweet
9.50K Views

Join the DZone community and get the full member experience.

Join For Free

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]";
 
APIPATH="https://build.phonegap.com/api/v1/apps";
FILEPATH="https://build.phonegap.com/apps/";

APIcall="$APIPATH/$project"
creds="$username:$password";

##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=${title##*:};
title=$(echo $title|sed 's/,//g');
title=$(echo $title|sed 's/"//g');
package=${package##*:};
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. ";
donecheck="";


echo "\nWaiting for rebuild to be done.";
while [$donecheck -eq ""]
do
	echo ".";
	sleep 10;
	donecheck=$(curl -s -u $creds  $APIcall | grep -Po '"android":"complete"');	
done
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

Build (game engine) Android (robot)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Container Orchestration Tools Comparison
  • Biometric Authentication: Best Practices
  • Chopping the Monolith: The Demo
  • Flask vs. Django: Which Python Framework to Choose?

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo