This guide provides a very quick easy guide to developing Gaia apps, including running Gaia inside desktop Firefox. This guide assumes that you know HTML5 technologies, have knowledge of MVC patterns and have keen interest in Firefox OS.
Note: It's important to note that this is not a particularly accurate representation of the experience of using Boot to Gecko on a real mobile device. Many hardware interface features don't work, for example, and Firefox nightly builds may be unstable. But it is still a valid way to get some high level testing done.
What do you need?
- First of all you need to have Git installed. If you prefer working in a visual environment, you might also consider installing the Github client (Github for Mac / Github for Windows). Git is essential for updating the code, promoting your changes, and seeing what other developers are working on.
- Next, you need to clone the Mozilla Gaia repository: https://github.com/mozilla-b2g/gaia. After this is done, you should use a terminal to enter the repository (
cd gaia) and then run the
DEBUG=1 makecommand to configure Gaia correctly for debugging.
- After you are done with setting up your workspace, you need to install the Nightly build of Firefox.
- In that Nightly build, you could also choose to have the Firefox Simulator Extension and App Manager Extension, depending on your preferred workflow (both are covered below). The App Manager extension should be pre-installed in the nightly build, but you'll need to install the Firefox OS simulator if desired.
- You will need to install the ADB helper for debugging on the remote device, AKA your phone.
- You might want to get a Firefox OS phone. It will show you various use information related to the start time of apps, frame rates, etc. Also, once you have the actual OS running on a device, you will be able to easily test all the supported device APIs.
Now that you have the basic workspace setup, lets get to the apps!
Firefox OS's default apps
The default HTML5 apps provided in the Gaia source code are as follows:
- Cost Control
The first app that gets launched when the phone starts is the System app. This app is responsible for opening and managing the Homescreen app. From the Homescreen app, you can launch the other apps to perform various functions. For example, the Dialer app gets launched from the Homescreen app when a user taps on the phone icon. This Dialer app can then launch the Contacts app when the user wants to see the list of contacts to dial.
Let’s explore some apps
The default apps are all contained in folders inside the
gaia/apps/ folder. Each Gaia app folder contains the following components:
manifest.webappfile: To store metadata about the app.
stylefolder: To store CSS files.
localesfolder: To store translated strings for different languages.
- An HTML file: usually (but not limited to)
Some apps may also have:
elementsfolder: To store other views in HTML files.
testfolder: To run the tests related to the application.
resourcesfolder: Contains other resources such as movies, sounds, etc.
.js files. Remember, it is an open source app/OS, so it is coded by many different people.
Note: This is the general layout for Gaia apps. Your own web apps only actually require a
manifest.webapp file; everything else is optional.
If you are experienced in web development, you will already have all you need to make some modifications to these apps. Get improving.
Let's fire up some apps
After you have made modifications to those applications, you will want to see the changes in action. You can either seem them in the Firefox OS simulator, running inside Firefox Nightly, or on a physical Firefox OS device.
Running in the Firefox OS simulator
To run the modified Gaia apps in the Firefox Simulator, open the simulator via Tools > Web Developer > Firefox OS Simulator. This should open up the simulator UI, then from here you can use the Add Directory/Add URL tools to add your modified Gaia apps into the simulator and run them. This is ok for a quick test, but the simulator doesn't have a lot of the features of Firefox OS available. The below options are better.
Running in Firefox Nightly
To run Gaia and view the apps in Firefox Nightly, you have to run a command with the following structure:
/path/to/firefoxnightly -profile /path/to/B2G/gaia/profile-debug -no-remote
For example, on Mac OS X, we ran the following command:
/Applications/FirefoxNightly.app/Contents/MacOS/firefox -profile /path/to/B2G/gaia/profile-debug -no-remote
-no-remote is needed to prevent reusing a running Firefox instance instead of creating a new one running the custom Gaia profile.
Running on a physical device
To push your modified Gaia to a physical Firefox OS device:
- Make sure you have
adbinstalled, or install ADB helper as described above.
- Check that your phone is successfully connected to your computer over
adbby entering the
adb devicescommand into your terminal.
- Enter the command
make reset-gaiafrom inside your Gaia directory to push it to your device over
There is an even easier way — as long as your device is running Firefox 1.2+, you can just run the modified app in the App Manager, as covered in the next section.
Debugging with the App Manager
After you are done building your app, you might want to debug it.
To do so, first of all get the App Manager and your physical device talking to one another, as shown in Using the App Manager.
Select the Contacts app (for example), then click on that debug button in your app section in the App Manager.
This will not only run the app on a device, but it opens up the debug window as well. Test it out by adding console or debug logs.
The following subsections answer some common questions about debugging apps using Gaia on the desktop.
Note: Refer to Hacking gaia for more make options that can be set that are useful for Gaia debugging.
Can I emulate high resolution devices inside the Firefox desktop browser?
- First of all, you can use the command
GAIA_DEV_PIXELS_PER_PX=1.5 DEBUG=1 maketo make sure the images look sharp on qHD and WVGA devices.
- Next, you can change browser density by opening the about:config page in Firefox and setting the
- Last, you can use the Responsive Design View to 320 x 533 px (which is the equivalent CSS pixel dimensions to 480 x 800 device pixels.)