blob: e26b3c74d72dd27332106893cc6af55b7e5f386c [file] [log] [blame]
Colin Cross8e404122014-02-06 14:45:37 -08001#
2# Copyright (C) 2008 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17###########################################################
18## Standard rules for building an application package.
19##
20## Additional inputs from base_rules.make:
21## LOCAL_PACKAGE_NAME: The name of the package; the directory
22## will be called this.
23##
24## MODULE, MODULE_PATH, and MODULE_SUFFIX will
25## be set for you.
26###########################################################
27
28# If this makefile is being read from within an inheritance,
29# use the new values.
30skip_definition:=
31ifdef LOCAL_PACKAGE_OVERRIDES
32 package_overridden := $(call set-inherited-package-variables)
33 ifeq ($(strip $(package_overridden)),)
34 skip_definition := true
35 endif
36endif
37
38ifndef skip_definition
39
40LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME))
41ifeq ($(LOCAL_PACKAGE_NAME),)
42$(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
43endif
44
45ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
46$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX)
47endif
48LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
49
50ifneq ($(strip $(LOCAL_MODULE)),)
51$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE)
52endif
53LOCAL_MODULE := $(LOCAL_PACKAGE_NAME)
54
Colin Cross8e404122014-02-06 14:45:37 -080055ifneq ($(strip $(LOCAL_MODULE_CLASS)),)
56$(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS)
57endif
58LOCAL_MODULE_CLASS := APPS
59
Ying Wangdd71c852015-12-04 13:59:18 -080060intermediates := $(call local-intermediates-dir)
61intermediates.COMMON := $(call local-intermediates-dir,COMMON)
62
Yohann Rousseld2a76c12015-02-05 16:10:58 +010063#################################
64include $(BUILD_SYSTEM)/configure_local_jack.mk
65#################################
Yohann Roussel37822c42015-01-09 10:36:40 +010066
Colin Cross8e404122014-02-06 14:45:37 -080067# Package LOCAL_MODULE_TAGS default to optional
68LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
69ifeq ($(LOCAL_MODULE_TAGS),)
70LOCAL_MODULE_TAGS := optional
71endif
72
73ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),)
74# Force localization check if it's not tagged as tests.
75LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z
76endif
77
Ying Wang4cb04992014-07-29 10:34:30 -070078need_compile_asset :=
Colin Cross8e404122014-02-06 14:45:37 -080079ifeq (,$(LOCAL_ASSET_DIR))
80LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
Ying Wang4cb04992014-07-29 10:34:30 -070081else
82need_compile_asset := true
Colin Cross8e404122014-02-06 14:45:37 -080083endif
84
Ying Wang61291922014-06-25 13:23:58 -070085# LOCAL_RESOURCE_DIR may point to resource generated during the build
86need_compile_res :=
Colin Cross8e404122014-02-06 14:45:37 -080087ifeq (,$(LOCAL_RESOURCE_DIR))
88 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
Ying Wang61291922014-06-25 13:23:58 -070089else
90 need_compile_res := true
Colin Cross8e404122014-02-06 14:45:37 -080091endif
92
93package_resource_overlays := $(strip \
94 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
95 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
96 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
97 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))))
98
Jaekyun Seok30706102017-02-02 00:44:58 +090099enforce_rro_enabled :=
100ifeq ($(BOARD_ENFORCE_RRO),true)
101 ifeq (,$(filter $(LOCAL_PACKAGE_NAME), $(BOARD_ENFORCE_RRO_EXEMPT_SOURCES)))
102 ifneq ($(package_resource_overlays),)
103 enforce_rro_enabled := true
104 endif
105 endif
106
107 ifdef enforce_rro_enabled
108 ifeq (,$(LOCAL_MODULE_PATH))
109 ifeq (true,$(LOCAL_PROPRIETARY_MODULE))
110 enforce_rro_enabled :=
111 else ifeq (true,$(LOCAL_OEM_MODULE))
112 enforce_rro_enabled :=
113 else ifeq (true,$(LOCAL_ODM_MODULE))
114 enforce_rro_enabled :=
115 endif
116 else ifeq ($(filter $(TARGET_OUT)/%,$(LOCAL_MODULE_PATH)),)
117 enforce_rro_enabled :=
118 endif
119 endif
120endif
121
122ifndef enforce_rro_enabled
Colin Cross8e404122014-02-06 14:45:37 -0800123LOCAL_RESOURCE_DIR := $(package_resource_overlays) $(LOCAL_RESOURCE_DIR)
Jaekyun Seok30706102017-02-02 00:44:58 +0900124endif
Colin Cross8e404122014-02-06 14:45:37 -0800125
Colin Cross2c321442014-02-12 13:06:30 -0800126all_assets := $(strip \
127 $(foreach dir, $(LOCAL_ASSET_DIR), \
128 $(addprefix $(dir)/, \
129 $(patsubst assets/%,%, \
130 $(call find-subdir-assets, $(dir)) \
131 ) \
132 ) \
133 ))
Colin Cross8e404122014-02-06 14:45:37 -0800134
Ying Wang4cb04992014-07-29 10:34:30 -0700135ifneq ($(all_assets),)
136need_compile_asset := true
137endif
138
Adam Lesinskie758f932016-02-26 11:13:43 -0800139my_res_package :=
Ying Wange295c3d2016-02-24 14:11:55 -0800140ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800141# In aapt2 the last takes precedence.
142my_resource_dirs := $(call reverse-list,$(LOCAL_RESOURCE_DIR))
Adam Lesinskie758f932016-02-26 11:13:43 -0800143my_res_dir :=
144my_overlay_res_dirs :=
145
146ifneq ($(LOCAL_STATIC_ANDROID_LIBRARIES),)
147# If we are using static android libraries, every source file becomes an overlay.
148# This is to emulate old AAPT behavior which simulated library support.
149my_res_dir :=
150my_overlay_res_dirs := $(my_resource_dirs)
151else
152# Without static libraries, the first directory is our directory, which can then be
153# overlaid by the rest. (First directory in my_resource_dirs is last directory in
154# $(LOCAL_RESOURCE_DIR) due to it being reversed.
155my_res_dir := $(firstword $(my_resource_dirs))
156my_overlay_res_dirs := $(wordlist 2,999,$(my_resource_dirs))
157endif
158
Ying Wangdd71c852015-12-04 13:59:18 -0800159my_overlay_resources := $(strip \
Adam Lesinskie758f932016-02-26 11:13:43 -0800160 $(foreach d,$(my_overlay_res_dirs),\
Ying Wangdd71c852015-12-04 13:59:18 -0800161 $(addprefix $(d)/, \
162 $(call find-subdir-assets,$(d)))))
163
Colin Crossfe109632016-11-29 11:12:56 -0800164my_res_resources := $(if $(my_res_dir),$(strip \
Ying Wangdd71c852015-12-04 13:59:18 -0800165 $(addprefix $(my_res_dir)/, \
Colin Crossfe109632016-11-29 11:12:56 -0800166 $(call find-subdir-assets,$(my_res_dir)))))
Ying Wangdd71c852015-12-04 13:59:18 -0800167
168all_resources := $(strip $(my_res_resources) $(my_overlay_resources))
169
170# The linked resource package.
171my_res_package := $(intermediates)/package-res.apk
172LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
173
Ying Wange5853972016-03-01 12:06:47 -0800174# Always run aapt2, because we need to at least compile the AndroidManifest.xml.
Ying Wangdd71c852015-12-04 13:59:18 -0800175need_compile_res := true
176
Ying Wange295c3d2016-02-24 14:11:55 -0800177else # LOCAL_USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800178all_resources := $(strip \
179 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
180 $(addprefix $(dir)/, \
181 $(patsubst res/%,%, \
182 $(call find-subdir-assets,$(dir)) \
183 ) \
184 ) \
185 ))
186
Adam Lesinski4c452052016-08-12 12:57:17 -0700187ifdef LOCAL_PACKAGE_SPLITS
188LOCAL_AAPT_FLAGS += $(addprefix --split ,$(LOCAL_PACKAGE_SPLITS))
189endif
190
Ying Wange295c3d2016-02-24 14:11:55 -0800191endif # LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800192
Ying Wang61291922014-06-25 13:23:58 -0700193ifneq ($(all_resources),)
194 need_compile_res := true
195endif
196
Colin Cross8e404122014-02-06 14:45:37 -0800197all_res_assets := $(strip $(all_assets) $(all_resources))
198
Colin Cross8e404122014-02-06 14:45:37 -0800199# If no assets or resources were found, clear the directory variables so
200# we don't try to build them.
Ying Wang4cb04992014-07-29 10:34:30 -0700201ifneq (true,$(need_compile_asset))
Colin Cross8e404122014-02-06 14:45:37 -0800202LOCAL_ASSET_DIR:=
203endif
Ying Wang61291922014-06-25 13:23:58 -0700204ifneq (true,$(need_compile_res))
Colin Cross8e404122014-02-06 14:45:37 -0800205LOCAL_RESOURCE_DIR:=
206R_file_stamp :=
207else
208# Make sure that R_file_stamp inherits the proper PRIVATE vars.
209# If R.stamp moves, be sure to update the framework makefile,
210# which has intimate knowledge of its location.
Ying Wang98ae7982014-12-18 14:53:52 -0800211R_file_stamp := $(intermediates.COMMON)/src/R.stamp
Colin Cross8e404122014-02-06 14:45:37 -0800212LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
213endif
214
215LOCAL_BUILT_MODULE_STEM := package.apk
Ying Wangaf9757e2014-07-17 21:24:42 -0700216LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
Colin Cross8e404122014-02-06 14:45:37 -0800217
218LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
219ifndef LOCAL_PROGUARD_ENABLED
220ifneq ($(DISABLE_PROGUARD),true)
221 LOCAL_PROGUARD_ENABLED :=full
222endif
223endif
224ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
225 # the package explicitly request to disable proguard.
226 LOCAL_PROGUARD_ENABLED :=
227endif
228proguard_options_file :=
229ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
Ying Wang61291922014-06-25 13:23:58 -0700230ifeq ($(need_compile_res),true)
Ying Wang98ae7982014-12-18 14:53:52 -0800231 proguard_options_file := $(intermediates.COMMON)/proguard_options
Ying Wang61291922014-06-25 13:23:58 -0700232endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800233endif # !custom
234LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
235
Colin Cross79e2f732016-12-21 14:29:13 -0800236ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200237ifndef LOCAL_JACK_PROGUARD_FLAGS
238 LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS)
239endif
240LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS)
Colin Cross79e2f732016-12-21 14:29:13 -0800241endif # LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200242
Colin Cross8e404122014-02-06 14:45:37 -0800243ifeq (true,$(EMMA_INSTRUMENT))
244ifndef LOCAL_EMMA_INSTRUMENT
245# No emma for test apks.
Ying Wang324ffb22015-11-06 11:22:28 -0800246ifeq (,$(LOCAL_INSTRUMENTATION_FOR))
Colin Cross8e404122014-02-06 14:45:37 -0800247LOCAL_EMMA_INSTRUMENT := true
248endif # No test apk
249endif # LOCAL_EMMA_INSTRUMENT is not set
250else
251LOCAL_EMMA_INSTRUMENT := false
252endif # EMMA_INSTRUMENT is true
253
254ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
255ifeq (true,$(EMMA_INSTRUMENT_STATIC))
Colin Cross79e2f732016-12-21 14:29:13 -0800256ifdef LOCAL_JACK_ENABLED
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100257# Jack supports coverage with Jacoco
Colin Cross79e2f732016-12-21 14:29:13 -0800258ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),)
259# Only add jacocoagent if the package contains some java code
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100260LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
Colin Cross79e2f732016-12-21 14:29:13 -0800261endif # Contains java code
262else
263LOCAL_STATIC_JAVA_LIBRARIES += emma
264endif # LOCAL_JACK_ENABLED
265else
Colin Cross8e404122014-02-06 14:45:37 -0800266ifdef LOCAL_SDK_VERSION
267ifdef TARGET_BUILD_APPS
Sebastien Hertz2319e562016-03-31 16:48:26 +0200268# In unbundled build, merge the coverage library into the apk.
Colin Cross79e2f732016-12-21 14:29:13 -0800269ifdef LOCAL_JACK_ENABLED
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100270# Jack supports coverage with Jacoco
Colin Cross79e2f732016-12-21 14:29:13 -0800271ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),)
272# Only add jacocoagent if the package contains some java code
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100273LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
Sebastien Hertz2319e562016-03-31 16:48:26 +0200274# Exclude jacoco classes from proguard
275LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
276LOCAL_JACK_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
Colin Cross79e2f732016-12-21 14:29:13 -0800277endif # Contains java code
278else # ! LOCAL_JACK_ENABLED
279LOCAL_STATIC_JAVA_LIBRARIES += emma
280endif # ! LOCAL_JACK_ENABLED
281else # ! TARGET_BUILD_APPS
282ifdef LOCAL_JACK_ENABLED
Sebastien Hertz2319e562016-03-31 16:48:26 +0200283# If build against the SDK in full build, core.jar is not used
284# so coverage classes are not present.
285# Jack needs jacoco on the classpath but we do not want it to be in
286# the final apk. While it is a static library, we add it to the
287# LOCAL_JAVA_LIBRARIES which are only present on the classpath.
288# Note: we have nothing to do for proguard since jacoco will be
289# on the classpath only, thus not modified during the compilation.
290LOCAL_JAVA_LIBRARIES += jacocoagent
Colin Cross79e2f732016-12-21 14:29:13 -0800291else # ! LOCAL_JACK_ENABLED
292# If build against the SDK in full build, core.jar is not used,
293# we have to use prebiult emma.jar to make Proguard happy;
294# Otherwise emma classes are included in core.jar.
295LOCAL_PROGUARD_FLAGS += -libraryjars $(EMMA_JAR)
296endif # ! LOCAL_JACK_ENABLED
297endif # ! TARGET_BUILD_APPS
Colin Cross8e404122014-02-06 14:45:37 -0800298endif # LOCAL_SDK_VERSION
Colin Cross79e2f732016-12-21 14:29:13 -0800299endif # EMMA_INSTRUMENT_STATIC
Colin Cross8e404122014-02-06 14:45:37 -0800300endif # LOCAL_EMMA_INSTRUMENT
301
302rs_compatibility_jni_libs :=
303
Ying Wanged0361f2015-04-19 09:55:39 -0700304ifeq ($(LOCAL_DATA_BINDING),true)
305data_binding_intermediates := $(intermediates.COMMON)/data-binding
306
307LOCAL_JAVACFLAGS += -processorpath $(DATA_BINDING_COMPILER) -s $(data_binding_intermediates)/anno-src
308LOCAL_JACK_FLAGS += --processorpath $(DATA_BINDING_COMPILER)
309
310LOCAL_STATIC_JAVA_LIBRARIES += databinding-baselibrary
311LOCAL_STATIC_JAVA_AAR_LIBRARIES += databinding-library databinding-adapters
312
313data_binding_res_in := $(LOCAL_RESOURCE_DIR)
314data_binding_res_out := $(data_binding_intermediates)/res
315
316# Replace with the processed merged res dir.
317LOCAL_RESOURCE_DIR := $(data_binding_res_out)
318
319LOCAL_AAPT_FLAGS += --auto-add-overlay --extra-packages com.android.databinding.library
320endif # LOCAL_DATA_BINDING
321
Ying Wange9dd9f22014-10-29 15:48:32 -0700322include $(BUILD_SYSTEM)/android_manifest.mk
323
Colin Cross8e404122014-02-06 14:45:37 -0800324#################################
325include $(BUILD_SYSTEM)/java.mk
326#################################
327
328LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
329ifeq ($(LOCAL_SDK_RES_VERSION),)
330 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
331endif
332
Colin Cross8e404122014-02-06 14:45:37 -0800333$(LOCAL_INTERMEDIATE_TARGETS): \
334 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
Colin Cross8e404122014-02-06 14:45:37 -0800335
Ying Wanged0361f2015-04-19 09:55:39 -0700336ifeq ($(LOCAL_DATA_BINDING),true)
337data_binding_stamp := $(data_binding_intermediates)/data-binding.stamp
338$(data_binding_stamp): PRIVATE_INTERMEDIATES := $(data_binding_intermediates)
339$(data_binding_stamp): PRIVATE_MANIFEST := $(full_android_manifest)
340# Generate code into $(LOCAL_INTERMEDIATE_SOURCE_DIR) so that the generated .java files
341# will be automatically picked up by function compile-java.
342$(data_binding_stamp): PRIVATE_SRC_OUT := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/data-binding
343$(data_binding_stamp): PRIVATE_XML_OUT := $(data_binding_intermediates)/xml
344$(data_binding_stamp): PRIVATE_RES_OUT := $(data_binding_res_out)
345$(data_binding_stamp): PRIVATE_RES_IN := $(data_binding_res_in)
346$(data_binding_stamp): PRIVATE_ANNO_SRC_DIR := $(data_binding_intermediates)/anno-src
347
348$(data_binding_stamp) : $(all_res_assets) $(full_android_manifest) \
349 $(DATA_BINDING_COMPILER)
350 @echo "Data-binding process: $@"
351 @rm -rf $(PRIVATE_INTERMEDIATES) $(PRIVATE_SRC_OUT) && \
352 mkdir -p $(PRIVATE_INTERMEDIATES) $(PRIVATE_SRC_OUT) \
353 $(PRIVATE_XML_OUT) $(PRIVATE_RES_OUT) $(PRIVATE_ANNO_SRC_DIR)
354 $(hide) java -classpath $(DATA_BINDING_COMPILER) android.databinding.tool.MakeCopy \
355 $(PRIVATE_MANIFEST) $(PRIVATE_SRC_OUT) $(PRIVATE_XML_OUT) $(PRIVATE_RES_OUT) $(PRIVATE_RES_IN)
356 $(hide) touch $@
357
358# Make sure the data-binding process happens before javac and generation of R.java.
359$(R_file_stamp) $(full_classes_compiled_jar) : $(data_binding_stamp)
360# The dependency path when jack is enabled
361$(built_dex_intermediate) : $(data_binding_stamp)
362endif # LOCAL_DATA_BINDING
363
Ying Wang61291922014-06-25 13:23:58 -0700364ifeq ($(need_compile_res),true)
Adam Lesinski4c452052016-08-12 12:57:17 -0700365
366###############################
367## APK splits
368built_apk_splits :=
369installed_apk_splits :=
370my_apk_split_configs :=
371
372ifdef LOCAL_PACKAGE_SPLITS
373my_apk_split_configs := $(LOCAL_PACKAGE_SPLITS)
374my_split_suffixes := $(subst $(comma),_,$(my_apk_split_configs))
375built_apk_splits := $(foreach s,$(my_split_suffixes),$(built_module_path)/package_$(s).apk)
376installed_apk_splits := $(foreach s,$(my_split_suffixes),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
377endif
378
Ying Wange295c3d2016-02-24 14:11:55 -0800379ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800380my_compiled_res_base_dir := $(intermediates)/flat-res
Ying Wange295c3d2016-02-24 14:11:55 -0800381my_generated_res_dirs := $(rs_generated_res_dir)
382my_generated_res_dirs_deps := $(RenderScript_file_stamp)
Adam Lesinskie758f932016-02-26 11:13:43 -0800383# Add AAPT2 link specific flags.
384$(my_res_package): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --no-static-lib-packages
Ying Wangdd71c852015-12-04 13:59:18 -0800385include $(BUILD_SYSTEM)/aapt2.mk
Ying Wange295c3d2016-02-24 14:11:55 -0800386else # LOCAL_USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800387
388# Since we don't know where the real R.java file is going to end up,
389# we need to use another file to stand in its place. We'll just
390# copy the generated file to src/R.stamp, which means it will
391# have the same contents and timestamp as the actual file.
392#
393# At the same time, this will copy the R.java file to a central
394# 'R' directory to make it easier to add the files to an IDE.
395#
Colin Cross8e404122014-02-06 14:45:37 -0800396
397$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
398 $(intermediates.COMMON)/public_resources.xml
399$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
400$(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT) | $(ACP)
401 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
Martin Arenlindfb6985e2015-09-15 15:52:56 +0200402 @rm -rf $@ && mkdir -p $(dir $@)
Colin Cross8e404122014-02-06 14:45:37 -0800403 $(create-resource-java-files)
Ying Wangdd71c852015-12-04 13:59:18 -0800404 $(call find-generated-R.java)
Colin Cross8e404122014-02-06 14:45:37 -0800405
406$(proguard_options_file): $(R_file_stamp)
407
Ying Wangdbe23f52014-03-25 14:42:46 -0700408resource_export_package :=
Colin Cross8e404122014-02-06 14:45:37 -0800409ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
410# Put this module's resources into a PRODUCT-agnositc package that
411# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
412# files.
413resource_export_package := $(intermediates.COMMON)/package-export.apk
414$(R_file_stamp): $(resource_export_package)
415
416# add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
417# can't know anything about PRODUCT. Clear it out just for this target.
418$(resource_export_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
419$(resource_export_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
420$(resource_export_package): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT)
421 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
422 $(create-empty-package)
423 $(add-assets-to-package)
424endif
425
Ying Wange295c3d2016-02-24 14:11:55 -0800426endif # LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800427
Colin Cross8e404122014-02-06 14:45:37 -0800428# Other modules should depend on the BUILT module if
429# they want to use this module's R.java file.
Colin Cross79e2f732016-12-21 14:29:13 -0800430$(LOCAL_BUILT_MODULE): $(R_file_stamp)
431
432ifdef LOCAL_JACK_ENABLED
433ifneq ($(built_dex_intermediate),)
434$(built_dex_intermediate): $(R_file_stamp)
435endif
436ifneq ($(noshrob_classes_jack),)
437$(noshrob_classes_jack): $(R_file_stamp)
438endif
439ifneq ($(full_classes_jack),)
440$(full_classes_jack): $(R_file_stamp)
441$(jack_check_timestamp): $(R_file_stamp)
442endif
443endif # LOCAL_JACK_ENABLED
444
445ifneq ($(full_classes_jar),)
446# If full_classes_jar is non-empty, we're building sources.
447# If we're building sources, the initial javac step (which
448# produces full_classes_compiled_jar) needs to ensure the
449# R.java and Manifest.java files have been generated first.
450$(full_classes_compiled_jar): $(R_file_stamp)
451endif
Colin Cross8e404122014-02-06 14:45:37 -0800452
Ying Wang61291922014-06-25 13:23:58 -0700453endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800454
455ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
456# We need to explicitly clear this var so that we don't
457# inherit the value from whomever caused us to be built.
458$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
459else
460# Most packages should link against the resources defined by framework-res.
461# Even if they don't have their own resources, they may use framework
462# resources.
Michael Wright0fb087f2015-11-06 15:20:51 +0000463ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current test_current,$(LOCAL_SDK_RES_VERSION))),)
Colin Cross8e404122014-02-06 14:45:37 -0800464# for released sdk versions, the platform resources were built into android.jar.
465framework_res_package_export := \
466 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
467framework_res_package_export_deps := $(framework_res_package_export)
468else # LOCAL_SDK_RES_VERSION
469framework_res_package_export := \
470 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
471# We can't depend directly on the export.apk file; it won't get its
472# PRIVATE_ vars set up correctly if we do. Instead, depend on the
473# corresponding R.stamp file, which lists the export.apk as a dependency.
474framework_res_package_export_deps := \
475 $(dir $(framework_res_package_export))src/R.stamp
476endif # LOCAL_SDK_RES_VERSION
Adam Lesinskide057c32014-03-13 18:48:27 -0700477all_library_res_package_exports := \
478 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700479 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700480 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk)
481
482all_library_res_package_export_deps := \
483 $(framework_res_package_export_deps) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700484 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700485 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp)
Ying Wangb5745642014-06-19 16:07:30 -0700486$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps)
Colin Cross8e404122014-02-06 14:45:37 -0800487$(LOCAL_INTERMEDIATE_TARGETS): \
Adam Lesinskide057c32014-03-13 18:48:27 -0700488 PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports)
Ying Wangdd71c852015-12-04 13:59:18 -0800489
Ying Wange295c3d2016-02-24 14:11:55 -0800490ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800491$(my_res_package) : $(all_library_res_package_export_deps)
492endif
Colin Cross8e404122014-02-06 14:45:37 -0800493endif # LOCAL_NO_STANDARD_LIBRARIES
494
495ifneq ($(full_classes_jar),)
496$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
Colin Cross79e2f732016-12-21 14:29:13 -0800497# Use the jarjar processed arhive as the initial package file.
498$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar)
Colin Cross8e404122014-02-06 14:45:37 -0800499$(LOCAL_BUILT_MODULE): $(built_dex)
Ying Wang33360dd2015-01-14 14:23:56 -0800500else
501$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE :=
Colin Cross79e2f732016-12-21 14:29:13 -0800502$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE :=
Colin Cross8e404122014-02-06 14:45:37 -0800503endif # full_classes_jar
504
Ying Wang96bcad42014-04-17 13:38:04 -0700505include $(BUILD_SYSTEM)/install_jni_libs.mk
Colin Cross8e404122014-02-06 14:45:37 -0800506
507# Pick a key to sign the package with. If this package hasn't specified
508# an explicit certificate, use the default.
509# Secure release builds will have their packages signed after the fact,
510# so it's ok for these private keys to be in the clear.
511ifeq ($(LOCAL_CERTIFICATE),)
512 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
513endif
514
515ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
516 # The special value "EXTERNAL" means that we will sign it with the
517 # default devkey, apply predexopt, but then expect the final .apk
518 # (after dexopting) to be signed by an outside tool.
519 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
520 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
521endif
522
523# If this is not an absolute certificate, assign it to a generic one.
524ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
525 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
526endif
527private_key := $(LOCAL_CERTIFICATE).pk8
528certificate := $(LOCAL_CERTIFICATE).x509.pem
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900529additional_certificates := $(foreach c,$(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
Colin Cross8e404122014-02-06 14:45:37 -0800530
531$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
532$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
533$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
534
535PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
536PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
537
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900538$(LOCAL_BUILT_MODULE): $(additional_certificates)
539$(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(additional_certificates)
Colin Cross8e404122014-02-06 14:45:37 -0800540
541# Define the rule to build the actual package.
Ying Wang8e20ef62014-06-24 20:01:52 -0700542# PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>.
543$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
544# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
545$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
Colin Cross8e404122014-02-06 14:45:37 -0800546ifneq ($(TARGET_BUILD_APPS),)
547 # Include all resources for unbundled apps.
548 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
549endif
550ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
Adam Lesinskie758f932016-02-26 11:13:43 -0800551 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG :=
552 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
Colin Cross8e404122014-02-06 14:45:37 -0800553else
Adam Lesinskie758f932016-02-26 11:13:43 -0800554 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG)
Ying Wang934008f2014-07-30 13:40:14 -0700555ifdef LOCAL_PACKAGE_SPLITS
Adam Lesinskie758f932016-02-26 11:13:43 -0800556 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
Ying Wang934008f2014-07-30 13:40:14 -0700557else
Adam Lesinskie758f932016-02-26 11:13:43 -0800558 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG)
Colin Cross8e404122014-02-06 14:45:37 -0800559endif
Ying Wang934008f2014-07-30 13:40:14 -0700560endif
Colin Cross79e2f732016-12-21 14:29:13 -0800561$(LOCAL_BUILT_MODULE): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS)
Ying Wangdd71c852015-12-04 13:59:18 -0800562$(LOCAL_BUILT_MODULE) : $(jni_shared_libraries)
Ying Wange295c3d2016-02-24 14:11:55 -0800563ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800564$(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package)
565$(LOCAL_BUILT_MODULE) : $(my_res_package) $(AAPT2) | $(ACP)
566else
567$(LOCAL_BUILT_MODULE) : $(all_res_assets) $(full_android_manifest) $(AAPT)
568endif
Colin Cross8e404122014-02-06 14:45:37 -0800569 @echo "target Package: $(PRIVATE_MODULE) ($@)"
Ying Wange295c3d2016-02-24 14:11:55 -0800570ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800571 $(call copy-file-to-new-target)
Ying Wang81ef4712016-03-31 10:10:42 -0700572else # ! LOCAL_USE_AAPT2
Colin Cross79e2f732016-12-21 14:29:13 -0800573ifdef LOCAL_JACK_ENABLED
Colin Cross8e404122014-02-06 14:45:37 -0800574 $(create-empty-package)
Colin Cross79e2f732016-12-21 14:29:13 -0800575else
576 $(if $(PRIVATE_SOURCE_ARCHIVE),\
577 $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@),\
578 $(create-empty-package))
579endif
Colin Cross8e404122014-02-06 14:45:37 -0800580 $(add-assets-to-package)
Ying Wange295c3d2016-02-24 14:11:55 -0800581endif # LOCAL_USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800582ifneq ($(jni_shared_libraries),)
583 $(add-jni-shared-libs-to-package)
584endif
Ying Wang8b27d182015-03-27 11:07:17 -0700585ifeq ($(full_classes_jar),)
586# We don't build jar, need to add the Java resources here.
587 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
Ying Wang3a61eeb2016-03-11 10:32:01 -0800588else # full_classes_jar
Colin Cross8e404122014-02-06 14:45:37 -0800589 $(add-dex-to-package)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800590endif # full_classes_jar
Colin Cross79e2f732016-12-21 14:29:13 -0800591ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200592 $(add-carried-jack-resources)
Colin Cross79e2f732016-12-21 14:29:13 -0800593endif
Colin Cross8e404122014-02-06 14:45:37 -0800594ifdef LOCAL_DEX_PREOPT
Ying Wang3a61eeb2016-03-11 10:32:01 -0800595ifneq ($(BUILD_PLATFORM_ZIP),)
596 @# Keep a copy of apk with classes.dex unstripped
597 $(hide) cp -f $@ $(dir $@)package.dex.apk
598endif # BUILD_PLATFORM_ZIP
Colin Cross8e404122014-02-06 14:45:37 -0800599ifneq (nostripping,$(LOCAL_DEX_PREOPT))
600 $(call dexpreopt-remove-classes.dex,$@)
601endif
602endif
Kenny Rootdff37552015-04-15 12:09:32 -0700603 $(sign-package)
Colin Cross8e404122014-02-06 14:45:37 -0800604
Ying Wang36142f62014-05-21 16:13:33 -0700605###############################
Ying Wang8070b202014-12-01 17:46:56 -0800606## Build dpi-specific apks, if it's apps_only build.
607ifdef TARGET_BUILD_APPS
608ifdef LOCAL_DPI_VARIANTS
609$(foreach d, $(LOCAL_DPI_VARIANTS), \
610 $(eval my_dpi := $(d)) \
611 $(eval include $(BUILD_SYSTEM)/dpi_specific_apk.mk))
612endif
613endif
614
615###############################
Ying Wang36142f62014-05-21 16:13:33 -0700616## Rule to build the odex file
617ifdef LOCAL_DEX_PREOPT
618$(built_odex): PRIVATE_DEX_FILE := $(built_dex)
Ying Wangdb48da72014-09-13 11:26:39 -0700619# Use pattern rule - we may have multiple built odex files.
620$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(built_dex)
Ying Wang994c2262014-05-28 13:34:59 -0700621 $(hide) mkdir -p $(dir $@) && rm -f $@
Ying Wang36142f62014-05-21 16:13:33 -0700622 $(add-dex-to-package)
623 $(hide) mv $@ $@.input
624 $(call dexpreopt-one-file,$@.input,$@)
625 $(hide) rm $@.input
626endif
627
Ying Wang1425e2d2014-07-22 15:42:11 -0700628###############################
629## APK splits
630ifdef LOCAL_PACKAGE_SPLITS
Ying Wang7f625aa2014-07-23 10:27:57 -0700631# The splits should have been built in the same command building the base apk.
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800632# This rule just runs signing.
Ying Wang7f625aa2014-07-23 10:27:57 -0700633# Note that we explicily check the existence of the split apk and remove the
634# built base apk if the split apk isn't there.
635# That way the build system will rerun the aapt after the user changes the splitting parameters.
Ying Wang1425e2d2014-07-22 15:42:11 -0700636$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
637$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
Ying Wang7f625aa2014-07-23 10:27:57 -0700638$(built_apk_splits) : $(built_module_path)/%.apk : $(LOCAL_BUILT_MODULE)
639 $(hide) if [ ! -f $@ ]; then \
640 echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \
641 rm $<; exit 1; \
642 fi
643 $(sign-package)
Ying Wang1425e2d2014-07-22 15:42:11 -0700644
645# Rules to install the splits
Dan Willemsen7f016152016-02-29 17:52:39 -0800646$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(built_module_path)/package_%.apk
Ying Wang7f625aa2014-07-23 10:27:57 -0700647 @echo "Install: $@"
648 $(copy-file-to-new-target)
Ying Wang1425e2d2014-07-22 15:42:11 -0700649
650# Register the additional built and installed files.
651ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
652ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
Ying Wang114a0fc2014-10-01 12:01:04 -0700653 $(foreach s,$(my_split_suffixes),$(built_module_path)/package_$(s).apk:$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Ying Wang1425e2d2014-07-22 15:42:11 -0700654
655# Make sure to install the splits when you run "make <module_name>".
Colin Cross33886702016-09-20 16:01:28 -0700656$(my_all_targets): $(installed_apk_splits)
Ying Wang16243612015-06-03 12:43:50 -0700657
658ifdef LOCAL_COMPATIBILITY_SUITE
Ying Wang16243612015-06-03 12:43:50 -0700659
Simran Basi6bea37c2017-02-16 18:04:10 -0800660$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
661 $(eval my_compat_dist_$(suite) := $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \
662 $(foreach s,$(my_split_suffixes),\
663 $(built_module_path)/package_$(s).apk:$(dir)/$(LOCAL_MODULE)_$(s).apk))))
Ying Wang16243612015-06-03 12:43:50 -0700664
Simran Basi6bea37c2017-02-16 18:04:10 -0800665$(call create-suite-dependencies)
666
Ying Wang16243612015-06-03 12:43:50 -0700667endif # LOCAL_COMPATIBILITY_SUITE
Ying Wang1425e2d2014-07-22 15:42:11 -0700668endif # LOCAL_PACKAGE_SPLITS
669
Colin Cross8e404122014-02-06 14:45:37 -0800670# Save information about this package
671PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
672PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
Colin Cross8e404122014-02-06 14:45:37 -0800673
674PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
675
Colin Cross8e404122014-02-06 14:45:37 -0800676endif # skip_definition
677
678# Reset internal variables.
679all_res_assets :=
Jaekyun Seok30706102017-02-02 00:44:58 +0900680
681ifdef enforce_rro_enabled
682 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
683 enforce_rro_use_res_lib := true
684 else
685 enforce_rro_use_res_lib := false
686 endif
687
688 ifdef LOCAL_MANIFEST_PACKAGE_NAME
689 enforce_rro_is_manifest_package_name := true
690 enforce_rro_manifest_package_info := $(LOCAL_MANIFEST_PACKAGE_NAME)
691 else
692 enforce_rro_is_manifest_package_name := false
693 enforce_rro_manifest_package_info := $(full_android_manifest)
694 endif
695
696$(call append_enforce_rro_sources, \
697 $(my_register_name), \
698 $(enforce_rro_is_manifest_package_name), \
699 $(enforce_rro_manifest_package_info), \
700 $(enforce_rro_use_res_lib), \
701 $(package_resource_overlays) \
702 )
703endif # enforce_rro_enabled