Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Latest commit

 

History

History
238 lines (189 loc) · 7.64 KB

File metadata and controls

238 lines (189 loc) · 7.64 KB
Developing add-ons for Firefox Mobile is still an experimental feature of the SDK. Although the SDK modules used are stable, the setup instructions and cfx commands are likely to change.

Developing for Firefox Mobile

Mozilla has recently decided to reimplement the UI for Firefox Mobile on Android using native Android widgets instead of XUL. With the add-on SDK you can develop add-ons that run on this new version of Firefox Mobile as well as on the desktop version of Firefox.

You can use the same code to target both desktop Firefox and Firefox Mobile, and just specify some extra options to cfx run, cfx test, and cfx xpi when targeting Firefox Mobile.

Right now only the following modules are fully functional:

We're working on adding support for the other modules.

This tutorial explains how to run SDK add-ons on an Android device connected via USB to your development machine. We'll use the Android Debug Bridge (adb) to communicate between the Add-on SDK and the device.

It's possible to use the Android emulator to develop add-ons for Android without access to a device, but it's slow, so for the time being it's much easier to use the technique described below.

Setting up the Environment

First you'll need an Android device capable of running the native version of Firefox Mobile. Then:

On the development machine:

  • install version 1.5 or higher of the Add-on SDK
  • install the correct version of the Android SDK for your device
  • using the Android SDK, install the Android Platform Tools

Next, attach the device to the development machine via USB.

Now open up a command shell. Android Platform Tools will have installed adb in the "platform-tools" directory under the directory in which you installed the Android SDK. Make sure the "platform-tools" directory is in your path. Then type:

adb devices

You should see some output like:

List of devices attached
51800F220F01564 device

(The long hex string will be different.)

If you do, then adb has found your device and you can get started.

Running Add-ons on Android

You can develop your add-on as normal, as long as you restrict yourself to the supported modules.

When you need to run the add-on, first ensure that Firefox is not running on the device. Then execute cfx run with some extra options:

cfx run -a fennec-on-device -b /path/to/adb --mobile-app fennec --force-mobile

See "cfx Options for Mobile Development" for the details of this command.

In the command shell, you should see something like:

Launching mobile application with intent name org.mozilla.fennec
Pushing the addon to your device
Starting: Intent { act=android.activity.MAIN cmp=org.mozilla.fennec/.App (has extras) }
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
Could not read chrome manifest 'file:///data/data/org.mozilla.fennec/chrome.manifest'.
info: starting
info: starting
zerdatime 1329258528988 - browser chrome startup finished.

This will be followed by lots of debug output.

On the device, you should see Firefox launch with your add-on installed.

console.log() output from your add-on is written to the command shell, just as it is in desktop development. However, because there's a lot of other debug output in the shell, it's not easy to follow. The command adb logcat prints adb's log, so you can filter the debug output after running the add-on. For example, on Mac OS X or Linux you can use a command like:

adb logcat | grep info:

Running cfx test is identical:

cfx test -a fennec-on-device -b /path/to/adb --mobile-app fennec --force-mobile

As you see in the quote above, cfx run and cfx test need four options to work on Android devices.

-a fennec-on-device This tells the Add-on SDK which application will host the add-on, and should be set to "fennec-on-device" when running an add-on on Firefox Mobile on a device.
-b /path/to/adb

As we've seen, cfx uses the Android Debug Bridge (adb) to communicate with the Android device. This tells cfx where to find the adb executable.

You need to supply the full path to the adb executable.

--mobile-app

This is the name of the Android intent. Its value depends on the version of Firefox Mobile that you're running on the device:

  • fennec: if you're running Nightly
  • fennec_aurora: if you're running Aurora
  • firefox_beta: if you're running Beta
  • firefox: if you're running Release

If you're not sure, run a command like this (on OS X/Linux, or the equivalent on Windows):

adb shell pm list packages | grep mozilla

You should see "package" followed by "org.mozilla." followed by a string. The final string is the name you need to use. For example, if you see:

package:org.mozilla.fennec

...then you need to specify:

--mobile-app fennec

This option is not required if you have only one Firefox application installed on the device.

--force-mobile

This is used to force compatibility with Firefox Mobile, and should always be used when running on Firefox Mobile.

Packaging Mobile Add-ons

To package a mobile add-on as an XPI, use the command:

cfx xpi --force-mobile

Actually installing the XPI on the device is a little tricky. The easiest way is probably to copy the XPI somewhere on the device:

adb push my-addon.xpi /mnt/sdcard/

Then open Firefox Mobile and type this into the address bar:

file:///mnt/sdcard/my-addon.xpi

The browser should open the XPI and ask if you want to install it.

Afterwards you can delete it using adb as follows:

adb shell
cd /mnt/sdcard
rm my-addon.xpi