Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

定制构建时 apps

作为一个开发者或设备厂商,您可能由于各种原因想要对 Friefox OS 首次启动时的 app 进行定制。本文则说明了完成该需求的不同机制。

Gaia 中的 App 存放位置

运行在 Firefox OS 中的 app 都位于 Gaia 源码树下,共有两个存储位置:

  • gaia/apps/: 系统默认的 app 存放在此处, 如 calendar, email, settings, 等。
  • gaia/dev-apps: 其他 app 的存放在此,如在自定义过程中包含的 app。

如果您想要在编译 Gaia/B2G 时忽略或添加这些 app, 有下面几种方式可以实现:

野蛮的定制方法

所谓“野蛮”的方法是指在编译前, 将不想要参与编译的 app 直接删除即可。

编辑配置列表

相比而言,更优雅的方法则是编辑 apps-*.list 文件 (位于不同的设备目录下,在  gaia/build/config/ 内部,如 phone/tablet/) ,将需要编译的 app 路径包括进去。例如,   gaia/build/config/phone/apps-production.list 格式如下所示:

apps/bluetooth
apps/bookmark
apps/browser
apps/calendar
apps/callscreen
etc.

注意,您也可以使用如下代码指定目录下的所有 app:

apps/*

至于在编译时,具体选择哪个  apps-*.list 文件的代码在 gaia/Makefile 文件中指定来,其形式如下所示:

GAIA_DEVICE_TYPE?=phone
  ...
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

最初, GAIA_APP_TARGET 变量被设置为 engineeringGAIA_DEVICE_TYPE 变量被设置成  phone, 因此默认情况下编译 Gaia 时会使用 gaia/config/phone/app-engineering.list (其中包括所有的测试,deomo 等)。

To specify usage of a different apps list you specify different options when running the make command. To build with gaia/build/config/phone/apps-production.list, for example, you'd use

PRODUCTION=1 make

If you specifically build with DEMO=1 specified, then it will use apps-demo.list. If you specifically build with DOGFOOD=1 specified, then it will use apps-dogfood.list.

You can completely override the decision by editing GAIA_APP_CONFIG in the gaia/Makefile, and providing your own apps-*.list file.

gaia/Android.mk 包括下面命令:

ifneq ($(filter user userdebug, $(TARGET_BUILD_VARIANT)),)
GAIA_MAKE_FLAGS += PRODUCTION=1
B2G_SYSTEM_APPS := 1
endif

When you build, if VARIANT=user or VARIANT=userdebug are set (these wind up getting reflected in the TARGET_BUILD_VARIANT variable), PRODUCTION=1 is automatically set when building Gaia.

注意: 要了解其他有效的 make 选项,请参考 make options 参考文档

使用市场化定制

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, specifying the location of the customization sample with the GAIA_DISTRIBUTION_DIR environment variable, like this:

GAIA_DISTRIBUTION_DIR=<DISTRIBUTION_PATH> make production

More customizations sample for distribution mechanism, please refer to https://github.com/mozilla-b2g/gaia/tree/master/customization

Customizations is its own separate topic entirely. To learn more about it, read our Market Customizations guide.

注意: 如果您希望在 Gaia 编译时包含一些自定义的外部 app, 则需要以指定的方式编译它们,并且将它们放在  gaia/dev-apps/ 文件夹中。请参考 Building Prebundled web apps  获取更多内容。

重要: 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.

 

文档标签和贡献者

 此页面的贡献者: chrisdavidmills, ReyCG_sub
 最后编辑者: chrisdavidmills,