Trang này nhằm tới các nhà phát triển của dự án Gaia. Nếu bạn đang tìm kiếm thông tin về việc làm thế nào để tạo dựng và chạy hệ điều hành Firefox( Firefox OS), bạn nên tham khảo Building and installing Firefox OS page thay thế.
Gaia là bộ sưu tập những web apps nhằm tạo nên bộ mặt cho Firefox OS. Mọi thứ bạn thấy trên màn hình Firefox được xây dựng bằng các công nghệ Web mở. Bao gồm màn hình chính (home screen) và toàn bộ các ứng dụng mặc định. Bài viết này cung cấp một hướng dẫn chi tiết để tinh chỉnh, sửa đổi cho Gaia.
Nhận mã nguồn
Để nhận mã nguồn của Gaia fork us on GitHub và sau đó tạo bản sao fork của bạn bằng cách sử dụng git.
$ git clone https://github.com/mozilla-b2g/gaia.git
Chạy Gaia
Bạn có thể chạy Gaia trên màn hình Desktop, trong Firefox hoặc trên một thiết bị di động tích hợp sẵn.
Màn hình nền B2G
Màn hình B2G là một loại màn hình nền xây dựng dựa trên ứng dụng thời gian chạy (runtime app) dùng trong các thiết bị sử dụng hệ điều hành Firefox, cái mà bạn có thể dùng để chạy Gaia trên màn hình nền máy tính của bạn.
Bạn có thể tải về một bản nightly build của B2G desktop từ Firefox Nightly site. Dựa trên phiên bản mà bạn đang nhắm tới, bạn có thể muốn một phiên bản cụ thể-mới nhất nào đó của mozilla-b2g18. Đã có sẵn các phiên bản cho Linux(32 bit và 64 bit), Mac OS X và Windows.
Nightly builds gồm phiên bản hiện tại của Gaia. Sau khi bạn đã tải về bản nén, tất cả những gì bạn cần làm là giải nén nó vào một thư mục và chạy tệp b2g trong thư mục vừa được giải nén.
$ cd b2g $ ./b2g
Để chạy B2G với phiên bản Gaia dành cho nhà phát triển, đầu tiên bạn cần tạo một hồ sơ cá nhân từ bản sao của bạn:
$ cd /path/to/gaia $ DEBUG=1 DESKTOP=0 make
Việc này sẽ tạo một mục trong thư mục gaia
của bạn, tên là profile
. Phần DEBUG
có vai trò như ứng dụng chủ nhà trên máy chủ web tích hợp sẵn, chứ không phải gói ứng dụng mặc định cần phải làm lại gói sau mỗi lần thay đổi. Bạn có thể tìm đường dẫn đến thư mục hồ sơ bằng cách nhìn vào dòng cuối của thư mục xuất sau khi chạy dòng lệnh trên, nó sẽ phải trông như thế này:
Profile Ready: please run [b2g|firefox] -profile /path/to/gaia/profile
Sau đó bạn có thể chạy màn hình nền B2G với hồ sơ bạn vừa tạo như sau:
$ ./b2g /path/to/gaia/profile
Nếu muốn bạn có thể tạo màn hình B2G của chính mình từ nguồn.
Ghi chú : Trên Mac OS X, tệp b2g
sẽ nằm trong B2G.app. Bạn sẽ cần chạy:
./B2G.app/Contents/MacOS/b2g /path/to/gaia/profile
Sử dụng Gaia trong Firefox
Gaia cũng có thể chạy trong Firefox. Nó sẽ cho bạn một số lợi ích trong việc có một vòng tròn phát triển (development cycle) siêu tốc, cùng với các công cụ phát triển Web tiêu chuẩn và các debugger.Xem Quickstart guide to Gaia development trong Firefox để biết chi tiết cách làm.
Sử dụng Gaia trên các thiết bị
Nếu bạn có một thiết bị di động tích hợp sẵn, bạn có thể chạy Gaia bằng cách cài nó vào hệ điều hành Firefox. Xem Building and installing Firefox OS để biết thêm chi tiết. Chúng tôi cũng có những tài liệu về how to test Firefox OS.
Kiểm tra đơn vị
Xem Gaia unit tests để biết các tài liệu về việc làm thế nào để tạo và chạy quá trình kiểm tra đơn vị cho Gaia.
Nộp hồ sơ lỗi
Các hồ sơ lỗi được nộp cho Bugzilla qua Firefox OS > Gaia. Đệ trình một lỗi mới qua tính năng của Gaia (hoặc một trong những tính năng phụ).
Đóng góp cho Gaia
Mozilla dựa trên những đóng góp từ nguồn cộng đồng mở giúp phát triển các ứng dụng Gaia, và chúng tôi mừng là bạn đã tham gia.
Một vài chỗ thú vị để tìm lỗi và bắt đầu làm việc:
Phong cách mã hóa cơ bản
- Nền:
- Đảm bảo rằng các tệp HTML đã được xác nhận
<!DOCTYPE html>
(có nghĩa là các văn bản HTML5). Nếu không Internet Explorer9 và mới hơn sẽ chạy nó dưới dạng tương thích sẵn. - Bao gồm
"use strict";
khai báo (bao gồm dấu ngoặc kép) đến các tệp JavaScript của bạn để đưa chúng vào chế độ nghiêm ngặt. - Luôn luôn dùng hai dấu cách để thụt đầu dòng, không nên dùng Tab.
- Sử dụng dấu ngắt dòng để tách các đoạn mã logic!
- Những tên tệp có nhiều từ nên dùng dấu gạch dưới để phân tách giữa các từ,
nhu_nay.js
. - Sử dụng ngoặc đơn thay ngoặc kép để thể hiện xâu.
Các điều cần biết
Sai:
if (expression) doSomething();
Đúng:
if (expression) { doSomething(); }
Nếu bạn làm việc trên ứng dụng hệ thống, xem hướng dẫn tại đây.
Trước khi đệ trình một bản patch, chúng tôi khuyến nghị bạn hãy sử dụng lệnh gjslint on it to check for any style errors:
gjslint --nojsdoc my_file.js
Submitting a patch
First file or assign a bug to yourself on Bugzilla, you'll need a Bugzilla account.
Then create a branch on your fork of Gaia:
$ git branch branchname $ git checkout branchname
Commit your changes:
$ git add /file/to/add $ git commit -m "Bug XXXXX - Fix the broken Gaia and save the world"
Push your branch:
$ git push origin branchname
Send a pull request by navigating to the branch in your fork on GitHub and finding the pull request button.
Note: Except under unusual circumstances, patches should be landing first on the master branch, not a release branch like v1-train, v1.3, etc. If they need to land on a release branch, they must go through the usual approval process as outlined on the B2G Landing wiki page.
To request a review of your patch, attach the pull request to the bug in Bugzilla by referencing the URL of the pull request, and set the review ("r") flag to "?" and enter the bugzilla ID of one of the module owners and peers (very important - otherwise your bug will not likely be seen by anyone). The Github tweaks for bugzilla extension on AMO can help automate this process by automatically creating the attachment and adding it to the bug; you will still need to set the review flag on Bugzilla.
The reviewer may ask you to make some changes; you may need to amend the original commit and force push it to the original branch/pull request. Once they're happy with your patch, they will merge it into the master branch for you. Before they do this they would prefer it if you could squash all your changes into a single commit, so your contribution can be tracked easily.
The person who merges the commit (usually the reviewer) would add a r=
flag in the comment of the merge commit.
Make options
you use the make
command inside the Gaia repo to create a Gaia profile that can be loaded onto your device or run in a B2G Desktop build. This section looks in detail at the different make options available.
There are many environment variables present in the Makefile. Do not depend on them as they may be removed in the future.
Created profiles are stored in /gaia/profile
, and contain the following items:
- defaults: Directory containing default settings to be reloaded after you reset the phone.
- extensions: Directory containing extensions.
- settings.json: Settings file.
- user.js: Another file containing more settings/preferences.
- webapps: Directory containing all the web apps that are to be installed on the phone.
Note: When you've already made a profile and you want to build a new one, you must delete the existing profile directory before trying to generate a new one.
Default
make
Push to device
make install-gaia make reset-gaia
With ADB (Android Debug Bridge) setup, these make targets will push Gaia to the device. reset-gaia
will purge all existing profiles, web apps and database entries (a new settings database will be initialized) before pushing Gaia from your working directory to your device ; install-gaia
will just push updates of Gaia. There is also a third option:
make profile
pushes only the existing profile.
Production make
PRODUCTION=1 make
This creates a production build of Gaia:
- Gaia is run as packaged apps, which are harder to debug, but are the best available state for apps in terms of available API permissions, etc.
- Test apps are not included in the build
- Remote debugging is turned off by default
- Lock screen is turned on (which in turn will cut USB connections)
- Marionette is turned off
- First time user experience is turned on
- Offline cache is used.
Note: You can also use the alias make production
.
Debug make
DEBUG=1 make
The DEBUG
variable runs Gaia as hosted apps on a built-in web server on a specific GAIA_PORT
, rather than the default of packaged apps which have to be re-packaged after every change; this makes things easier to test. Launching the profile with the latest Firefox Nightly will also give you nice B2G specific panels on the Firefox Developer Tools.
In addition:
- Test apps are included in the build.
- Remote debugging is turned on by default.
- Lock screen is turned off (USB connections won't be interrupted.)
- Marionette is turned on, which is needed when running Gaia unit tests.
- First time user experience is turned off.
- Offline cache is not used, even if it is generated.
Device debug make
DEVICE_DEBUG=1 make
This disables screen lock on the device, and enables debugging with the ADB tool, so is useful for device debugging.
In Firefox OS version > 1.2, specify this param when you want to debug Firefox OS webapps with the App Manager.
Enable remote debugging
REMOTE_DEBUGGER=1
This enables remote debugging on the device, the same as using the option in the developer settings.
Debug desktop make
DEBUG=1 DESKTOP=0 make
This option creates a desktop debug version, for running inside B2G desktop.
Build specific apps
APP=system make APP=system make install-gaia
With a profile already exists, APP
allow you to specify which app to re-package, instead of re-packing and re-push all the Gaia apps.
Official Mozilla branding make
MOZILLA_OFFICIAL=1 make
Use this to make an official Mozilla-branded build.
Dogfood make
DOGFOOD=1 make
Dogfood is turned on.
System apps make
B2G_SYSTEM_APPS=1 make
This environment variable lets you push an app to /system/b2g
instead of /data/local
. You should use this when you work with a user build. This variable is automatically set when running make production
. This can be used for install-gaia
or reset-gaia
too.
JavaScript optimization make
GAIA_OPTIMIZE=1 make
This triggers an optimization pass on Gaia's JavaScript, concatenating/compressing the files. This is automatically set when running make production
. This can be used for install-gaia
or reset-gaia
too.
High resolution image assets
GAIA_DEV_PIXELS_PER_PX=1.5 make
When packaging the app, this option replaces images with their *@1.5x.(gif|jpg|png)
equivalents if such images exist. You need to use the above option as part of a standard make
command, for example:
GAIA_DEV_PIXELS_PER_PX=1.5 make reset-gaia GAIA_DEV_PIXELS_PER_PX=1.5 make install-gaia
Gaia is currently targetting the following screen resolutions:
- qHD: ~540×960; device pixel ratio = 1.6875
- WVGA: ~480×800; device pixel ratio = 1.5
- HBGA (320x240); device pixel ratio = 1
use GAIA_DEV_PIXELS_PER_PX
to make sure the images looks sharp on qHD and WVGA devices. see A pixel is not a pixel for more information about device pixels per css pixels.
Disable first time user guide
NOFTU=1
Disable the first time user guide with this environment variable.
Distribution and market customization build
GAIA_DISTRIBUTION_DIR=./dir
Read Market Customizations for more details.
Reference Workloads
Reference workloads allow developers/testers to quickly install a large amount of data in several applications, typically on a newly-flashed phone.
The commands are (from the gaia directory):
make reference-workload-light
- 200 contacts
- 200 sms messages
- 50 dialer history entries
- 20 gallery images
- 20 songs
- 5 videos
make reference-workload-medium
- 500 contacts
- 500 sms messages
- 100 dialer history entries
- 50 gallery images
- 50 songs
- 10 videos
make reference-workload-heavy
- 1000 contacts
- 1000 sms messages
- 200 dialer history entries
- 100 gallery images
- 100 songs
- 20 videos
make reference-workload-x-heavy
- 2000 contacts
- 2000 sms messages
- 500 dialer history entries
- 250 gallery images
- 250 songs
- 50 videos
These targets accept the APP
environment variable, or an APPS
environment variable that should contain the app names separated by a space, e.g.:
APP=sms make reference-workload-light APPS="sms communications/contacts" make reference-workload-heavy
The apps available are:
APPS="gallery music video communications/contacts sms communications/dialer"
In order to install music (songs) with reference workloads, the utility mid3v2 must be installed. This utility can be installed with:
sudo apt-get install python-mutagen
If you run Fedora or RHEL instead, use:
sudo yum install python-mutagen
Documentation make
Gaia docs can be built, via jsdoc3. To generate these, you can use the following command:
make docs
Enabling IME layout and dictionaries
To enable keyboard IME layout and dictionaries enabled, use following command structure:
GAIA_KEYBOARD_LAYOUTS=en,zh-Hant-Zhuyin,el,de,fr,zh-Hans-Pinyin make
Customizing the build-time apps
The apps that run on Firefox OS are all contained within the Gaia source tree, in one of two locations:
gaia/apps
: This is where the system default apps are found, such ascalendar
,email
,settings
, etc.gaia/external-apps
: This is where the Firefox Marketplace app is found (marketplace.firefox.com
), and where apps subsequently installed by the user are stored.gaia/showcase-apps
: This is a container for multiple showcase apps, for example a 3D Crystal Skull to show off WebGL performance on the device.gaia/test-apps
: This directory is a repository for simple tests, designed to test simple B2G features.gaia/external-apps
: This directory contains more tests.- There may be oters too, depending on the version of Gaia you have cloned.
Note: If you are building B2G rather than Gaia, the paths will of course have B2G/
on the front, e.g. B2G/gaia/apps
and B2G/gaia/external-apps
.
If you want to omit some of these apps from your build of Gaia/B2G, you can do this in a few different ways:
-
The "brute force" method is to simply delete the apps you don't want to be present at build time, before building.
-
The more refined method is to edit the
gaia/build/config/apps-*.list
files to include the paths to the apps you want to include at build time. For example,gaia/build/config/apps-production.list
looks something like this:apps/* external-apps/* outoftree_apps/*
But you could also include specific apps rather than just picking them all, for example:
apps/clock
The mechanism for choosing which
apps-*.list
file is used during the build to determine the available apps is contained insidegaia/Makefile
:GAIA_APP_TARGET?=engineering ... ifeq ($(MAKECMDGOALS), demo) GAIA_DOMAIN=thisdomaindoesnotexist.org GAIA_APP_TARGET=demo else ifeq ($(MAKECMDGOALS), dogfood) DOGFOOD=1 else ifeq ($(MAKECMDGOALS), production) PRODUCTION=1 endif ... ifeq ($(PRODUCTION), 1) GAIA_OPTIMIZE=1 GAIA_APP_TARGET=production endif ifeq ($(DOGFOOD), 1) GAIA_APP_TARGET=dogfood endif ... ifndef GAIA_APP_CONFIG GAIA_APP_CONFIG=build$(SEP)config$(SEP)apps-$(GAIA_APP_TARGET).list endif
Initially, the
GAIA_APP_TARGET
variable is set toengineering
, so by default building gaia from source will useapp-engineering.list
(which includes all the tests, demos, etc.):make
To specify usage of a different apps list you specify different options when running the make command. To build with
apps-production.list
, for example, you'd usePRODUCTION=1 make
- If you specifically build with
DEMO=1
specified, then it will useapps-demo.list
. - If you specifically build with
DOGFOOD=1
specified, then it will useapps-dogfood.list
. - You can completely override the decision by using
GAIA_APP_CONFIG
and providing your ownapps-*.list
file.
gaia/Android.mk
contains these lines:ifneq ($(filter user userdebug, $(TARGET_BUILD_VARIANT)),) GAIA_MAKE_FLAGS += PRODUCTION=1 B2G_SYSTEM_APPS := 1 endif
When you build, if
VARIANT=user
orVARIANT=userdebug
are set (these wind up getting reflected in theTARGET_BUILD_VARIANT
variable),PRODUCTION=1
is automatically set when building gaia. - If you specifically build with
-
The third, and most refined (but most complex) method is to use customizations. These allow you to specify build-time customization instructions in separate difrectories, without modifying the core Gaia repo. You can include your own customizations in distinct directories, or use the preexisting directories that come with the source.
For example, the basic Firefox tablet customized app list is defined in
apps.list
under thedistribution_tablet
folder (gaia/distribution_tablet
). These customizations can be applied at build time using options like this:GAIA_DISTRIBUTION_DIR=distribution_tablet make
Note: Customizations is its own separate topic entirely. To learn more about it, read Market Customizations.
Note: If you want to include custom external apps as part of your Gaia build, you need to build them in a specific way, and then place them into the
gaia/external-apps/
folder. Read Building Prebundled web apps to find out how.
Important: If you are a device vendor creating a custom B2G/Gaia build for distribution, you need to satisfy certain criteria before you are allowed to include the Firefox Marketplace app on your phones/tablets/etc. Contact Mozilla for more details.
Contacting the Team
- Gaia Mailing List
- #gaia IRC channel on irc.mozilla.org