Many aspects of Firefox OS development require installation of ADB, the Android Debug Bridge. This article explains how to do that, and shares some common useful ADB commands.
You can download and install
adb as part of the Android SDK package, for Mac, Linux or Windows — visit the Get the Android SDK page.
Or, you can install it as an addon to Firefox, which is the fastest way.
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
Or for Fedora 19/20/21:
sudo yum install android-tools
Or on OSX using Homebrew:
brew install android-platform-tools
If your distribution does not have packages for
adb available (i.e. 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
$SDK_HOME with the location of the android sdk, to your
~/.bashrc or equivalent.
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
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.
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