Gaia/Hacking: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
(Redirected page to mdn:Firefox OS/Developing Gaia)
 
(47 intermediate revisions by 20 users not shown)
Line 1: Line 1:
Gaia is the collection of [https://developer.mozilla.org/apps web apps] which make up the front end of [http://www.mozilla.org/firefoxos/ Firefox OS] (codenamed Boot to Gecko).
#REDIRECT [[mdn:Firefox OS/Developing Gaia]]
 
Everything you see on the screen in Firefox OS is built using open web technologies, including the homescreen and dialer.
 
== Running Gaia Apps ==
 
There are three ways to run Gaia apps:
* Firefox Nightly
* B2G Desktop
* B2G on a device
 
=== Firefox Nightly ===
Most Gaia apps will run in a nightly build of the Firefox web browser which you can download from [http://nightly.mozilla.org/ nightly.mozilla.org].
 
To help you get started running and hacking on Gaia apps, Gaia comes with a script to automatically generate a special Firefox profile which includes a simple web server.
 
You can start by cloning [https://github.com/mozilla-b2g/gaia Gaia's git repository on Github], or by forking Gaia and cloning your fork.
 
$ git clone git://github.com/mozilla-b2g/gaia.git gaia
 
Then to generate the Gaia profile:
  $ cd gaia
  $ DEBUG=1 make
 
Then run Firefox Nightly from the command line, with the generated profile:
 
  $ /path/to/firefox -profile /path/to/gaia/profile
 
(substituting /path/to/firefox and /path/to/gaia for the paths you downloaded Firefox and cloned Gaia to, respectively)
 
'''Note:''' Unfortunately Gaia's system app (inside which the homescreen and other apps run) does not currently work in Firefox. Therefore you'll need to load an app directly by its URL, e.g. http://browser.gaiamobile.org:8080
 
Running Gaia apps using this method has the advantage of giving you access to all the development tools built into Firefox. The disadvantage is that not all apps currently work in this way, and they may not behave ''exactly'' as they would on a device.
 
=== B2G Desktop ===
 
B2G Desktop is a desktop build of the B2G app runtime used on devices where all apps should run as they would on a device, including the homesreen.
 
==== Nightly Builds ====
 
You can download a nightly build of B2G Desktop from [http://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/latest-mozilla-central/ http://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/latest-mozilla-central/] for Linux, OS X and Windows.
 
You still need to separately clone and "build" Gaia, in the same way as when using Firefox Nightly:
 
$ git clone git://github.com/mozilla-b2g/gaia.git gaia
$ cd gaia
$ DEBUG=1 make
 
Then you just run with B2G Desktop instead of Firefox:
 
$ /path/to/b2g -profile /path/to/gaia/profile
 
(or "/path/to/b2g/B2G.app/Contents/MacOS/b2g -profile /path/to/gaia/profile" on OS X)
 
To update gaia you run the following command inside the Gaia directory:
 
$ git pull
 
(or "git fetch && git merge upstream/master" if you checked out from your own clone).
 
==== Build Your Own ====
 
If you prefer you can build B2G Desktop yourself by checking it out from mozilla-central using Mercurial:
 
$ hg clone http://hg.mozilla.org/mozilla-central src
 
Before building, create a file called .mozconfig to configure some options, here's an example:
 
mk_add_options MOZ_OBJDIR=../build
mk_add_options MOZ_MAKE_FLAGS="-j9 -s"
ac_add_options --enable-application=b2g
ac_add_options --disable-libjpeg-turbo
 
# This option is required if you want to be able to run Gaia's tests
ac_add_options --enable-tests
# turn on mozTelephony/mozSms interfaces
# Only turn this line on if you actually have a dev phone
# you want to forward to. If you get crashes at startup,
# make sure this line is commented.
#ac_add_options --enable-b2g-ril
 
Then run make inside the mozilla-central directory:
 
$ make -f client.mk build
 
'''Note:''' Ensure you're using python2 and not python3 as the build will fail with python3.
 
The build will appear in ../build (or whatever MOZ_OBJDIR is set to in your .mozconfig) and will take a ''long'' time the first time you build. Once it's built you can run B2G with:
 
$ ../build/dist/bin/b2g -profile /path/to/gaia/profile
 
(substituting /path/to/gaia with the path to which you cloned Gaia).
 
When you want to update your own B2G Desktop build do:
 
$ hg pull && hg update
 
In the gaia directory:
 
$ git pull
 
=== B2G on a device ===
 
It is possible to build & run Firefox OS on a limited number of smartphones. Please see documentation [https://github.com/mozilla-b2g/B2G/blob/master/README.md here].
 
== Unit Tests ==
 
Gaia comes with a suite of unit tests, which you can run using the built-in Test Agent app (by running it in B2G desktop, B2G on a device, or by navigating to http://test-agent.gaiamobile.org:8080 in Firefox Nightly).
 
See [https://developer.mozilla.org/en-US/docs/Mozilla/Boot_to_Gecko/Gaia_Unit_Tests here] for more information on writing and running unit tests for Gaia.
 
== Contributing Code ==
 
Mozilla depends on contributions from the open source community to help develop Gaia apps and we'd love you to get invovled.
 
Some great places to find some bugs to start hacking on:
* [https://bugzilla.mozilla.org/buglist.cgi?quicksearch=component:gaia%20sw:polish%20@nobody;list_id=4566236 Unowned Gaia polish bugs on Bugzilla]
* [http://www.joshmatthews.net/bugsahoy/?b2g=1 Mentored bugs]
 
To submit a patch:
* Assign an un-owned Gaia bug to yourself on [https://bugzilla.mozilla.org/buglist.cgi?product=Boot2Gecko&component=Gaia&resolution=--- Bugzilla]
* Fork Gaia on Github
* Develop in a branch on your fork (remembering to keep to the [https://wiki.mozilla.org/Gaia#Coding_Style Coding Style guidelines] for Gaia)
* Push to your branch
* Send a pull request
* Paste a link to the pull request in the bug on Bugzilla
* Your patch will be reviewed on Github
* To make changes in response to the code review, just push more commits to the same branch and your pull request will get updated automatically
* Once the reviewer is happy with your patch, they will merge it into the master branch for you
 
== Contacting The Team ==
* [https://lists.mozilla.org/listinfo/dev-gaia Gaia Mailing List]
* #gaia IRC channel on irc.mozilla.org
 
 
== Tips ==
=== Rendering glitches on Linux ===
If you're running on Linux and find you're seeing lots of annoying rendering glitches, try turning off layer acceleration with a pref in your gaia/profile/prefs.js file:
 
user_pref("layers.acceleration.disabled", true);
 
=== Port Forwarding ===
To forward the socket on the phone to the desktop (for desktop development), you first need to get rilproxy to expose it as such, rather than exposing it to Gecko. In the gaia directory:
 
  $ make forward
 
This runs the commands:
$ adb shell touch /data/local/rilproxyd
$ adb shell killall rilproxy
$ adb forward tcp:6200 localreserved:rilproxyd
 
The file located at /data/local/rilproxyd will be deleted once the rilproxy daemon will start again. As a consequence you have to do this manipulation every time your device restarts.
 
=== Restarting B2G on a device from the desktop ===
adb shell killall b2g
 
=== B2G Desktop JavaScript Console ===
 
You can run B2G Desktop with the JavaScript console by using the -jsconsole flag
 
=== Launching an app directly ===
 
A "--runapp" option has been added to the B2G Desktop command-line to automatically start an application. The system app is loaded and everything happens like normal; this is not like the old trick where we loaded your app instead of the system app.
 
"--runapp" takes an argument that it normalizes by lower-casing and removing dashes and spaces, and then checks the argument against the similarly normalized app names from app manifests. For example, the name of the e-mail app is currently "E-Mail", but "--runapp email" will run it. Partial matching is not supported right now, but you can enhance b2g/chrome/content/runapp.js if your app name is unwieldy.
 
If you invoke "--runapp" without an argument (or an empty argument), the command will print out a list of all the apps it knows about as well as a brief usage message.
 
One important note is that this command disables the lock-screen as part of its magic and does not re-enable it. The assumption is that you won't use this command on a profile where you are testing the lock screen, or will turn it back on manually. Feel free to enhance the command to behave better if this is a problem for you.
 
In summary:
 
./b2g -profile /path/to/your/gaia/profile --runapp email
 
runs the e-mail app.
 
=== reset-gaia and install-gaia make targets ===
 
The reset-gaia and install-gaia make targets can be used interchangeably. reset-gaia will purge all the existing profiles, database before push Gaia from your working directory (new setting database will also be initialized); install-gaia will just push updates of Gaia.
 
=== Blank screen when B2G Desktop starts ===
When you start b2g using b2g -profile $GAIA/profile a blank screen shows up and you see an error Cannot reach app://system.gaiamobile.org. To fix this there are a couple of things you can check
 
* Rebuild the gaia profile using DEBUG=1 make profile in the $GAIA directory
* Run b2g again
* If this doesn't fix it, check if there is any other process listening on port 8080. The default profile of gaia starts httpd.js, which listens on port 8080. When running a debug profile, b2g connects to localhost:8080. If some other process is running on port 8080, b2g will fail to display the home screen of gaia
** To find out if this is the case, you can enable logging on httpd.js. The httpd.js in the profile resides in this location - $GAIA/profile/extensions/httpd/content/httpd.js. Edit the variable var DEBUG=false; to change the DEBUG to true. Save the file and restart b2g. On the console now, you will be able to view the httpd's logs

Latest revision as of 02:50, 25 October 2014