Bug 1160563 - Part 2: Make ANDROID_ASSETS_DIRS a moz.build variable. r=gps

We have had singular ANDROID_ASSETS_DIR in Makefile.in for a while.
Fennec itself does not use the existing Makefile.in Android code, for
complicated historical reasons.

This makes the existing variable moz.build-only; generalizes the
existing variable to an ordered list; and adds the equivalent use of
the new list to the Fennec build, with a simple example asset.

This patch also updates the packager to include assets packed into the
gecko.ap_.  Without the packager change, the assets/ directory in the
ap_ gets left out of the final apk.  This whole approach is totally
non-standard but is more or less required to support our single-locale
repack scheme.
This commit is contained in:
Nick Alexander 2015-08-12 11:04:03 -07:00
parent c2c01b0bb8
commit 2cb62bed1d
12 changed files with 48 additions and 9 deletions

View File

@ -11,8 +11,6 @@ ANDROID_EXTRA_JARS += \
$(srcdir)/robotium-solo-4.3.1.jar \
$(NULL)
ANDROID_ASSETS_DIR := $(TESTPATH)/assets
_JAVA_HARNESS := \
Actions.java \
Assert.java \

View File

@ -7,6 +7,9 @@
DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
base = '/mobile/android/tests/browser/robocop/'
ANDROID_ASSETS_DIRS += [base + 'assets']
TEST_HARNESS_FILES.testing.mochitest += [
base + 'robocop.ini',
base + 'robocop_autophone.ini',

View File

@ -18,7 +18,7 @@ endif #} JAVAFILES
ifdef ANDROID_APK_NAME #{
android_res_dirs := $(or $(ANDROID_RES_DIRS),$(srcdir)/res)
_ANDROID_RES_FLAG := $(addprefix -S ,$(android_res_dirs))
_ANDROID_ASSETS_FLAG := $(addprefix -A ,$(ANDROID_ASSETS_DIR))
_ANDROID_ASSETS_FLAG := $(if $(ANDROID_ASSETS_DIRS),$(addprefix -A ,$(ANDROID_ASSETS_DIRS)))
android_manifest := $(or $(ANDROID_MANIFEST_FILE),AndroidManifest.xml)
GENERATED_DIRS += classes
@ -45,7 +45,7 @@ $(ANDROID_APK_NAME).ap_: .aapt.deps ;
# resource files one subdirectory below the parent resource directory.
android_res_files := $(wildcard $(addsuffix /*,$(wildcard $(addsuffix /*,$(android_res_dirs)))))
.aapt.deps: $(android_manifest) $(android_res_files) $(wildcard $(ANDROID_ASSETS_DIR))
.aapt.deps: $(android_manifest) $(android_res_files) $(wildcard $(ANDROID_ASSETS_DIRS))
@$(TOUCH) $@
$(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar $(_ANDROID_RES_FLAG) $(_ANDROID_ASSETS_FLAG) \
-J ${@D} \

View File

@ -0,0 +1 @@
This is an example asset.

View File

@ -420,6 +420,7 @@ $(1): $$(call mkdir_deps,$(filter-out ./,$(dir $(3) $(4) $(5)))) $(2)
$(if $(MOZ_ANDROID_MAX_SDK_VERSION),--max-res-version $(MOZ_ANDROID_MAX_SDK_VERSION),) \
--auto-add-overlay \
$$(addprefix -S ,$$(ANDROID_RES_DIRS)) \
$$(addprefix -A ,$$(ANDROID_ASSETS_DIRS)) \
$(if $(extra_res_dirs),$$(addprefix -S ,$$(extra_res_dirs)),) \
$(if $(extra_packages),--extra-packages $$(extra_packages),) \
--custom-package org.mozilla.gecko \

View File

@ -764,6 +764,10 @@ ANDROID_GENERATED_RESFILES += [
'res/values/strings.xml',
]
ANDROID_ASSETS_DIRS += [
'/mobile/android/app/assets',
]
# We do not expose MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN here because that
# would leak the value to build logs. Instead we expose the token quietly where
# appropriate in Makefile.in.

View File

@ -142,6 +142,7 @@ class MachCommands(MachCommandBase):
srcdir('base/src/webrtc_video_capture/java', 'media/webrtc/trunk/webrtc/modules/video_capture/android/java/src')
srcdir('base/src/webrtc_video_render/java', 'media/webrtc/trunk/webrtc/modules/video_render/android/java/src')
srcdir('base/src/main/res', 'mobile/android/base/resources')
srcdir('base/src/main/assets', 'mobile/android/app/assets')
srcdir('base/src/crashreporter/res', 'mobile/android/base/crashreporter/res')
manifest_path = os.path.join(self.topobjdir, 'mobile', 'android', 'gradle.manifest')

View File

@ -26,6 +26,7 @@ import mozpack.path as mozpath
from .common import CommonBackend
from ..frontend.data import (
AndroidAssetsDirs,
AndroidResDirs,
AndroidEclipseProjectData,
BrandingFiles,
@ -71,6 +72,7 @@ from ..util import (
from ..makeutil import Makefile
MOZBUILD_VARIABLES = [
b'ANDROID_ASSETS_DIRS',
b'ANDROID_GENERATED_RESFILES',
b'ANDROID_RES_DIRS',
b'ASFLAGS',
@ -603,6 +605,10 @@ class RecursiveMakeBackend(CommonBackend):
for p in obj.paths:
backend_file.write('ANDROID_RES_DIRS += %s\n' % p.full_path)
elif isinstance(obj, AndroidAssetsDirs):
for p in obj.paths:
backend_file.write('ANDROID_ASSETS_DIRS += %s\n' % p.full_path)
else:
return
obj.ack()

View File

@ -699,6 +699,14 @@ VARIABLES = {
file.
""", 'export'),
'ANDROID_ASSETS_DIRS': (ContextDerivedTypedListWithItems(Path, List), list,
"""Android assets directories.
This variable contains a list of directories containing static
files to package into an 'assets' directory and merge into an
APK file.
""", 'export'),
'ANDROID_ECLIPSE_PROJECT_TARGETS': (dict, dict,
"""Defines Android Eclipse project targets.

View File

@ -975,3 +975,14 @@ class AndroidResDirs(ContextDerived):
def __init__(self, context, paths):
ContextDerived.__init__(self, context)
self.paths = paths
class AndroidAssetsDirs(ContextDerived):
"""Represents Android assets directories."""
__slots__ = (
'paths',
)
def __init__(self, context, paths):
ContextDerived.__init__(self, context)
self.paths = paths

View File

@ -24,6 +24,7 @@ import reftest
import mozinfo
from .data import (
AndroidAssetsDirs,
AndroidResDirs,
BrandingFiles,
ConfigFileSubstitution,
@ -700,14 +701,18 @@ class TreeMetadataEmitter(LoggingMixin):
for name, data in context.get('ANDROID_ECLIPSE_PROJECT_TARGETS', {}).items():
yield ContextWrapped(context, data)
paths = context.get('ANDROID_RES_DIRS')
if paths:
for (symbol, cls) in [
('ANDROID_RES_DIRS', AndroidResDirs),
('ANDROID_ASSETS_DIRS', AndroidAssetsDirs)]:
paths = context.get(symbol)
if not paths:
continue
for p in paths:
if isinstance(p, SourcePath) and not os.path.isdir(p.full_path):
raise SandboxValidationError('Directory listed in '
'ANDROID_RES_DIRS is not a directory: \'%s\'' %
p.full_path, context)
yield AndroidResDirs(context, paths)
'%s is not a directory: \'%s\'' %
(symbol, p.full_path), context)
yield cls(context, paths)
if passthru.variables:
yield passthru

View File

@ -470,6 +470,7 @@ INNER_MAKE_PACKAGE = \
( cd $(STAGEPATH)$(MOZ_PKG_DIR)$(_BINPATH) && \
unzip -o $(_ABS_DIST)/gecko.ap_ && \
rm $(_ABS_DIST)/gecko.ap_ && \
$(ZIP) -r9D $(_ABS_DIST)/gecko.ap_ assets && \
$(ZIP) $(if $(ALREADY_SZIPPED),-0 ,$(if $(MOZ_ENABLE_SZIP),-0 ))$(_ABS_DIST)/gecko.ap_ $(ASSET_SO_LIBRARIES) && \
$(ZIP) -r9D $(_ABS_DIST)/gecko.ap_ $(DIST_FILES) -x $(NON_DIST_FILES) $(SZIP_LIBRARIES) && \
$(if $(filter-out ./,$(OMNIJAR_DIR)), \