Gaia Hacks – Part 2

Some useful commands that i came across  while contributing to OPEN SOURCE  to  Mozilla  (Firefox OS: Gaia hack)

All commands are used on Linux system (Ubuntu 14.04)

Hack – 1.  Flashing your Geeksphone(Keon) with Latest nightly

Get the latest stable and nightly builds as self contained downloads for flashing your phone from here :


Download your particular build and extract the archive to your filesystem. The archive contains the images and commands required to flash the phone using Windows, Mac OS, or Linux. Before attempting to flash the phone make sure that you have enabled Remote debugging on the phone. This option can be set by launching the Settings app and navigating to the Device information -> More information -> Developer tab. Also do not attempt to flash the phone if the power level is below 50%.

Enabling remote debugging on the Firefox OS Settings app

For Linux

To flash a Keon from Ubuntu add the following rules to /etc/udev/rules.d/51-android.rules

SUBSYSTEM==”usb”, ATTR{idVendor}==”05c6″, ATTR{idProduct}==”8013″, MODE=”0666″
SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”d00d”, MODE=”0666″

Open a Terminal (control-alt-t on Ubuntu) window and cd to the directory containing the extracted files. Run:


This should flash the new image to the phone. The phone will need to be set up again as all data will be cleared.

Hack – 2.  Flashing Latest Gaia repo to device

This development require installation of adb, the Android Debug Bridge. So first of all install adb .

Newer Linux distributions have adb already in their repositories. For Ubuntu 12.10 and later, run the following command:

sudo apt-get install android-tools-adb

Troubleshooting (If you get any error)

If you’re using a 64-bit install, and you get a “File not found” error when running ‘adb’ even though the file is present, you’ll need to install 32-bit compatibility libraries. To do this with apt:

sudo apt-get install ia32-libs

Restarting the b2g Process (if not running)

b2g is the equivalent of a XULRunner application running on the phone atop an Android-based kernel. Sometimes you may want to restart it; this is a way to reset the application environment without rebooting the entire device. You can do this by entering the following on your terminal while your device is connected to your computer (or while running the debugger):

adb shell killall b2g

Push to device

make install-gaia
make reset-gaia

With ADB (Android Debug Bridge) setup, these make targets will push Gaia to the device. install-gaia will just push updates of Gaia from your working directory to your device. reset-gaia will purge all existing configuration, profiles, web apps and database entries (a new settings database will be initialized) before pushing Gaia.

Now if you want to flash the master branch of your gaia repo

git checkout master
make install-gaia installs everything

if you want to flash some different branch you created, let’s say  branch :-  newbug

git checkout newbug
make install-gaia installs everything

If you want to flash any particular app say SMS instead of complete gaia repo

git checkout master (or newbug whichever you want)
APP=sms make install-gaia

One of my friend ask me how to make my own build app let’s say fitness app as default one (like Sms,Contact,Calendar which cannot be uninstall)

Simple Solution : Copy and paste your  app folder  in :  cd gaia/apps folder

Then push that app or complete repo to your device using above commands.

Hack – 3.   How to resolve ‘whitespace errors’ ? 

Whitespace errors ??   What the HELL is this (this was my reaction when i encountered first time 🙂 )

When you made some changes to your files (say some js file), then sometime it give whitespace errors (Check using jshint tool) when commiting changes which is difficult to find.If you are here, you’ve seen the trailing whitespace errors shown by Git when committing changes.

Following shell scripts will help you…

  1. In a terminal of some sort, go to your working git repository ($GIT_DIR) : (In our case : cd gaia)
    cd $GIT_DIR
  2. Now open a new file for writing:
    cat > .git/hooks/pre-commit
  3. Paste the following code in the terminal:

    if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
    # Initial commit: diff against an empty tree object
    # Find files with trailing whitespace
    for FILE in `exec git diff-index --check --cached $against -- | sed '/^[+-]/d' | sed -r 's/:[0-9]+:.*//' | uniq` ; do
    # Fix them!
    sed -i 's/[[:space:]]*$//' "$FILE"
    git add "$FILE"

  4. Hit “Enter” and then “Control+D” to end editing.
  5. Finally, make the file executable:
    chmod +x .git/hooks/pre-commit

Now every time you commit changes, Git will run the hook and clear trailing whitespace before actually saving the changes.

If you feel any problem then ping on irc channel #gaia or #b2g or join the gaia mailing list. You can ping me too on .

More blogs are coming on gaia and related hacks

Till then Happy Hacking !  🙂