Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Many aspects of Firefox OS development require installation of ADB, the Android Debug Bridge, and the Fastboot tool. This article explains how to do that, and shares some common useful ADB commands.

Installing ADB and fastboot

You can download and install adb and fastboot as part of the Android SDK package, for Mac, Linux or Windows — visit the Get the Android SDK page.

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 android-tools-fastboot

On Fedora 22/23/24:

sudo dnf install android-tools

Or on OSX using Homebrew:

brew install android-platform-tools

If your distribution does not have packages for adb available (e.g. Ubuntu 12.04 or Fedora 17/18), you'll need to install the Android SDK starter package for your platform (you'll want the ADT Bundle, not the SDK Tools Only option). Then run their package manager, $SDK_HOME/tools/android, and use the GUI to install "Android SDK Platform-tools".

Find out where adb is installed (usually in usr/bin, possibly additionally inside adt/platform-tools, depending on how you installed it). Be sure to add this directory to your PATH. This can be done by adding the line

PATH=$SDK_HOME:$PATH

replacing $SDK_HOME with the location of the android sdk, to your ~/.bashrc or equivalent.

Troubleshooting

This section contains some troubleshooting tips.

General

In general if you find that your Firefox OS device is not being recognised by adb devices or WebIDE or whatever, you are advised to try unplugging and replugging the USB cable, turning Debugging via USB off and on again (make sure it was on in the first place), and also trying adb kill-server/adb start-server to restart the adb server if all else fails.

adb still doesn't recognise the device — udev issues

Linux has the extra setup step in that you need to configure the udev rule for your phone before it will be recognised.

On top of this, some devices may require extra work. The Flame device has specific issues because it has a modeswitch rule that renders it invisible to adb devices (see the solution.)

General advice for all devices is to check your device's USB vendor ID by running the lsusb command with your phone plugged in, and search your Linux distribution's udev rules (typically under /lib/udev) for the id. If it is listed, then you need to make sure the Android udev rules file (look for 51_android.rules in the udev rules directory) is processed last to override the pre-configured rules that might stop the device working. This can be done by renaming said file to a higher number than the other files start with (as the files are run alphabetically), for example 99_android.rules. At this point, restart the system and try again.

64-bit install "File not found" 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

If your device cannot be found when running 'adb devices', click here to follow steps to fix it.

Common ADB commands

The following sections explain some common, useful adb commands.

Restarting the b2g process

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

Enabling port forwarding for debugging

To simply enable port forwarding (for example if you are using the App Manager to debug apps on a Firefox OS device), enter the following command into your terminal:

adb forward tcp:6000 localfilesystem:/data/local/debugger-socket

You'll need to do this every time the phone is restarted or unplugged then re-plugged. You can change the socket number if required.

Forwarding ports to a local machine

To forward ports to a local machine, you will need to download the netcat and ssh binaries, and run the following commands:

# this is an awful hack but does in fact work...
host$ adb forward tcp:7979 tcp:6969

# make some named pipes so that we can make a bidirectional netcat
phone$ mknod readback p
host$ mknod readback p

# this sets up a one time use connection to back to the host
# listen on ports 6969 and 5959 and forward all the information between them
phone$ ./netcat -l -p 6969 < readback | ./netcat -l -p 5959 > readback
# connect to port 7979 (port 6969 on the device) and the local ssh server and forward all information between them 
host$ ./netcat localhost 7979 < readback | ./netcat localhost 22 > readback

# now when we connect to port 5959 on the phone it will be like connecting to ssh server on the host 

# use the netcat reversal to set up an ssh connection back to the host and forward port 9999 on the device to 'localhost:8000' (this could be anything like 'google.com:80')
phone$ ./ssh localhost -p 5959 -L 9999:localhost:8000

This will forward port 9999 on the device to the host's port 8000.

Alternatively you can use an ssh server (dropbear and host_key) directly on the device, using the following commands:

phone$ DROPBEAR_PASSWORD=root ./dropbear -p 9000 -F -v -a -r host_key ./dropbear
host$ adb forward tcp:8888 tcp:9000
# public key authentication has been hard coded to succeed (make sure you have a public key for ssh to use)
host$ ssh -vvv root@localhost -p 8888 -R 9999:people.mozilla.org:80

Further resources:

Document Tags and Contributors

 Last updated by: chrisdavidmills,