blob: cb77e76099937d4f70096619b7a98616383df46d [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
Yohann Rousseld2a76c12015-02-05 16:10:58 +010060#################################
61include $(BUILD_SYSTEM)/configure_local_jack.mk
62#################################
Yohann Roussel37822c42015-01-09 10:36:40 +010063
Colin Cross8e404122014-02-06 14:45:37 -080064# Package LOCAL_MODULE_TAGS default to optional
65LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
66ifeq ($(LOCAL_MODULE_TAGS),)
67LOCAL_MODULE_TAGS := optional
68endif
69
70ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),)
71# Force localization check if it's not tagged as tests.
72LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z
73endif
74
Ying Wang1425e2d2014-07-22 15:42:11 -070075ifdef LOCAL_PACKAGE_SPLITS
76LOCAL_AAPT_FLAGS += $(addprefix --split ,$(LOCAL_PACKAGE_SPLITS))
77endif
78
Ying Wang4cb04992014-07-29 10:34:30 -070079need_compile_asset :=
Colin Cross8e404122014-02-06 14:45:37 -080080ifeq (,$(LOCAL_ASSET_DIR))
81LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
Ying Wang4cb04992014-07-29 10:34:30 -070082else
83need_compile_asset := true
Colin Cross8e404122014-02-06 14:45:37 -080084endif
85
Ying Wang61291922014-06-25 13:23:58 -070086# LOCAL_RESOURCE_DIR may point to resource generated during the build
87need_compile_res :=
Colin Cross8e404122014-02-06 14:45:37 -080088ifeq (,$(LOCAL_RESOURCE_DIR))
89 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
Ying Wang61291922014-06-25 13:23:58 -070090else
91 need_compile_res := true
Colin Cross8e404122014-02-06 14:45:37 -080092endif
93
94package_resource_overlays := $(strip \
95 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
96 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
97 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
98 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))))
99
100LOCAL_RESOURCE_DIR := $(package_resource_overlays) $(LOCAL_RESOURCE_DIR)
101
Colin Cross2c321442014-02-12 13:06:30 -0800102all_assets := $(strip \
103 $(foreach dir, $(LOCAL_ASSET_DIR), \
104 $(addprefix $(dir)/, \
105 $(patsubst assets/%,%, \
106 $(call find-subdir-assets, $(dir)) \
107 ) \
108 ) \
109 ))
Colin Cross8e404122014-02-06 14:45:37 -0800110
Ying Wang4cb04992014-07-29 10:34:30 -0700111ifneq ($(all_assets),)
112need_compile_asset := true
113endif
114
Colin Cross8e404122014-02-06 14:45:37 -0800115all_resources := $(strip \
116 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
117 $(addprefix $(dir)/, \
118 $(patsubst res/%,%, \
119 $(call find-subdir-assets,$(dir)) \
120 ) \
121 ) \
122 ))
123
Ying Wang61291922014-06-25 13:23:58 -0700124ifneq ($(all_resources),)
125 need_compile_res := true
126endif
127
Colin Cross8e404122014-02-06 14:45:37 -0800128all_res_assets := $(strip $(all_assets) $(all_resources))
129
Ying Wang98ae7982014-12-18 14:53:52 -0800130intermediates.COMMON := $(call local-intermediates-dir,COMMON)
131
Colin Cross8e404122014-02-06 14:45:37 -0800132# If no assets or resources were found, clear the directory variables so
133# we don't try to build them.
Ying Wang4cb04992014-07-29 10:34:30 -0700134ifneq (true,$(need_compile_asset))
Colin Cross8e404122014-02-06 14:45:37 -0800135LOCAL_ASSET_DIR:=
136endif
Ying Wang61291922014-06-25 13:23:58 -0700137ifneq (true,$(need_compile_res))
Colin Cross8e404122014-02-06 14:45:37 -0800138LOCAL_RESOURCE_DIR:=
139R_file_stamp :=
140else
141# Make sure that R_file_stamp inherits the proper PRIVATE vars.
142# If R.stamp moves, be sure to update the framework makefile,
143# which has intimate knowledge of its location.
Ying Wang98ae7982014-12-18 14:53:52 -0800144R_file_stamp := $(intermediates.COMMON)/src/R.stamp
Colin Cross8e404122014-02-06 14:45:37 -0800145LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
146endif
147
148LOCAL_BUILT_MODULE_STEM := package.apk
Ying Wangaf9757e2014-07-17 21:24:42 -0700149LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
Colin Cross8e404122014-02-06 14:45:37 -0800150
151LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
152ifndef LOCAL_PROGUARD_ENABLED
153ifneq ($(DISABLE_PROGUARD),true)
154 LOCAL_PROGUARD_ENABLED :=full
155endif
156endif
157ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
158 # the package explicitly request to disable proguard.
159 LOCAL_PROGUARD_ENABLED :=
160endif
161proguard_options_file :=
162ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
Ying Wang61291922014-06-25 13:23:58 -0700163ifeq ($(need_compile_res),true)
Ying Wang98ae7982014-12-18 14:53:52 -0800164 proguard_options_file := $(intermediates.COMMON)/proguard_options
Ying Wang61291922014-06-25 13:23:58 -0700165endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800166endif # !custom
167LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
168
Yohann Roussel37822c42015-01-09 10:36:40 +0100169ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200170ifndef LOCAL_JACK_PROGUARD_FLAGS
171 LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS)
172endif
173LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS)
Yohann Roussel37822c42015-01-09 10:36:40 +0100174endif # LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200175
Colin Cross8e404122014-02-06 14:45:37 -0800176ifeq (true,$(EMMA_INSTRUMENT))
177ifndef LOCAL_EMMA_INSTRUMENT
178# No emma for test apks.
Ying Wang324ffb22015-11-06 11:22:28 -0800179ifeq (,$(LOCAL_INSTRUMENTATION_FOR))
Colin Cross8e404122014-02-06 14:45:37 -0800180LOCAL_EMMA_INSTRUMENT := true
181endif # No test apk
182endif # LOCAL_EMMA_INSTRUMENT is not set
183else
184LOCAL_EMMA_INSTRUMENT := false
185endif # EMMA_INSTRUMENT is true
186
187ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
188ifeq (true,$(EMMA_INSTRUMENT_STATIC))
189LOCAL_STATIC_JAVA_LIBRARIES += emma
190else
191ifdef LOCAL_SDK_VERSION
192ifdef TARGET_BUILD_APPS
193# In unbundled build merge the emma library into the apk.
194LOCAL_STATIC_JAVA_LIBRARIES += emma
195else
196# If build against the SDK in full build, core.jar is not used,
197# we have to use prebiult emma.jar to make Proguard happy;
198# Otherwise emma classes are included in core.jar.
199LOCAL_PROGUARD_FLAGS += -libraryjars $(EMMA_JAR)
200endif # full build
201endif # LOCAL_SDK_VERSION
202endif # EMMA_INSTRUMENT_STATIC
203endif # LOCAL_EMMA_INSTRUMENT
204
205rs_compatibility_jni_libs :=
206
Ying Wange9dd9f22014-10-29 15:48:32 -0700207include $(BUILD_SYSTEM)/android_manifest.mk
208
Colin Cross8e404122014-02-06 14:45:37 -0800209#################################
210include $(BUILD_SYSTEM)/java.mk
211#################################
212
213LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
214ifeq ($(LOCAL_SDK_RES_VERSION),)
215 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
216endif
217
Colin Cross8e404122014-02-06 14:45:37 -0800218$(LOCAL_INTERMEDIATE_TARGETS): \
219 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
Ying Wangefb93582014-07-19 17:00:50 -0700220ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION)))
Colin Cross8e404122014-02-06 14:45:37 -0800221$(LOCAL_INTERMEDIATE_TARGETS): \
222 PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION)
223else
224$(LOCAL_INTERMEDIATE_TARGETS): \
225 PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
226endif
227
Ying Wang61291922014-06-25 13:23:58 -0700228ifeq ($(need_compile_res),true)
Colin Cross8e404122014-02-06 14:45:37 -0800229
230# Since we don't know where the real R.java file is going to end up,
231# we need to use another file to stand in its place. We'll just
232# copy the generated file to src/R.stamp, which means it will
233# have the same contents and timestamp as the actual file.
234#
235# At the same time, this will copy the R.java file to a central
236# 'R' directory to make it easier to add the files to an IDE.
237#
Colin Cross8e404122014-02-06 14:45:37 -0800238
239$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
240 $(intermediates.COMMON)/public_resources.xml
241$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
242$(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT) | $(ACP)
243 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
Martin Arenlindfb6985e2015-09-15 15:52:56 +0200244 @rm -rf $@ && mkdir -p $(dir $@)
Colin Cross8e404122014-02-06 14:45:37 -0800245 $(create-resource-java-files)
246 $(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
247 -name Manifest.java 2> /dev/null`; do \
248 dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_MANIFEST_FILE`; \
249 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
250 $(ACP) -fp $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
251 done;
252 $(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
253 -name R.java 2> /dev/null`; do \
254 dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_R_FILE`; \
255 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
256 $(ACP) -fp $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
257 || exit 31; \
258 $(ACP) -fp $$GENERATED_R_FILE $@ || exit 32; \
Martin Arenlindfb6985e2015-09-15 15:52:56 +0200259 done;
260 @# Ensure that the target file is always created, i.e. also in case we did not
261 @# enter the GENERATED_R_FILE-loop above. This avoids unnecessary rebuilding.
262 $(hide) touch $@
Colin Cross8e404122014-02-06 14:45:37 -0800263
264$(proguard_options_file): $(R_file_stamp)
265
Ying Wangdbe23f52014-03-25 14:42:46 -0700266resource_export_package :=
Colin Cross8e404122014-02-06 14:45:37 -0800267ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
268# Put this module's resources into a PRODUCT-agnositc package that
269# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
270# files.
271resource_export_package := $(intermediates.COMMON)/package-export.apk
272$(R_file_stamp): $(resource_export_package)
273
274# add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
275# can't know anything about PRODUCT. Clear it out just for this target.
276$(resource_export_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
277$(resource_export_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
278$(resource_export_package): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT)
279 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
280 $(create-empty-package)
281 $(add-assets-to-package)
282endif
283
284# Other modules should depend on the BUILT module if
285# they want to use this module's R.java file.
286$(LOCAL_BUILT_MODULE): $(R_file_stamp)
287
Yohann Roussel37822c42015-01-09 10:36:40 +0100288ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200289ifneq ($(built_dex_intermediate),)
290$(built_dex_intermediate): $(R_file_stamp)
291endif
292ifneq ($(noshrob_classes_jack),)
293$(noshrob_classes_jack): $(R_file_stamp)
294endif
295ifneq ($(full_classes_jack),)
296$(full_classes_jack): $(R_file_stamp)
297endif
Yohann Roussel37822c42015-01-09 10:36:40 +0100298endif # LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200299
Colin Cross8e404122014-02-06 14:45:37 -0800300ifneq ($(full_classes_jar),)
301# If full_classes_jar is non-empty, we're building sources.
302# If we're building sources, the initial javac step (which
303# produces full_classes_compiled_jar) needs to ensure the
304# R.java and Manifest.java files have been generated first.
305$(full_classes_compiled_jar): $(R_file_stamp)
306endif
307
Ying Wang61291922014-06-25 13:23:58 -0700308endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800309
310ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
311# We need to explicitly clear this var so that we don't
312# inherit the value from whomever caused us to be built.
313$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
314else
315# Most packages should link against the resources defined by framework-res.
316# Even if they don't have their own resources, they may use framework
317# resources.
Ying Wangefb93582014-07-19 17:00:50 -0700318ifneq ($(filter-out current system_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current,$(LOCAL_SDK_RES_VERSION))),)
Colin Cross8e404122014-02-06 14:45:37 -0800319# for released sdk versions, the platform resources were built into android.jar.
320framework_res_package_export := \
321 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
322framework_res_package_export_deps := $(framework_res_package_export)
323else # LOCAL_SDK_RES_VERSION
324framework_res_package_export := \
325 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
326# We can't depend directly on the export.apk file; it won't get its
327# PRIVATE_ vars set up correctly if we do. Instead, depend on the
328# corresponding R.stamp file, which lists the export.apk as a dependency.
329framework_res_package_export_deps := \
330 $(dir $(framework_res_package_export))src/R.stamp
331endif # LOCAL_SDK_RES_VERSION
Adam Lesinskide057c32014-03-13 18:48:27 -0700332all_library_res_package_exports := \
333 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700334 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700335 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk)
336
337all_library_res_package_export_deps := \
338 $(framework_res_package_export_deps) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700339 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700340 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp)
341
Ying Wangb5745642014-06-19 16:07:30 -0700342$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps)
Colin Cross8e404122014-02-06 14:45:37 -0800343$(LOCAL_INTERMEDIATE_TARGETS): \
Adam Lesinskide057c32014-03-13 18:48:27 -0700344 PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports)
Colin Cross8e404122014-02-06 14:45:37 -0800345endif # LOCAL_NO_STANDARD_LIBRARIES
346
347ifneq ($(full_classes_jar),)
348$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
Ying Wang33360dd2015-01-14 14:23:56 -0800349# Use the jarjar processed arhive as the initial package file.
350$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar)
Colin Cross8e404122014-02-06 14:45:37 -0800351$(LOCAL_BUILT_MODULE): $(built_dex)
Ying Wang33360dd2015-01-14 14:23:56 -0800352else
353$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE :=
354$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE :=
Colin Cross8e404122014-02-06 14:45:37 -0800355endif # full_classes_jar
356
Ying Wang96bcad42014-04-17 13:38:04 -0700357include $(BUILD_SYSTEM)/install_jni_libs.mk
Colin Cross8e404122014-02-06 14:45:37 -0800358
359# Pick a key to sign the package with. If this package hasn't specified
360# an explicit certificate, use the default.
361# Secure release builds will have their packages signed after the fact,
362# so it's ok for these private keys to be in the clear.
363ifeq ($(LOCAL_CERTIFICATE),)
364 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
365endif
366
367ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
368 # The special value "EXTERNAL" means that we will sign it with the
369 # default devkey, apply predexopt, but then expect the final .apk
370 # (after dexopting) to be signed by an outside tool.
371 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
372 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
373endif
374
375# If this is not an absolute certificate, assign it to a generic one.
376ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
377 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
378endif
379private_key := $(LOCAL_CERTIFICATE).pk8
380certificate := $(LOCAL_CERTIFICATE).x509.pem
381
382$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
383$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
384$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
385
386PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
387PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
388
389$(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(foreach c,\
390 $(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
391
392# Define the rule to build the actual package.
393$(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN)
Ying Wang8e20ef62014-06-24 20:01:52 -0700394# PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>.
395$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
396# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
397$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
Colin Cross8e404122014-02-06 14:45:37 -0800398ifneq ($(TARGET_BUILD_APPS),)
399 # Include all resources for unbundled apps.
400 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
401endif
402ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
403 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG :=
404 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
405else
406 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG)
Ying Wang934008f2014-07-30 13:40:14 -0700407ifdef LOCAL_PACKAGE_SPLITS
408 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
409else
Colin Cross8e404122014-02-06 14:45:37 -0800410 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG)
411endif
Ying Wang934008f2014-07-30 13:40:14 -0700412endif
Fredrik Roubertcc93f0c2015-01-28 21:29:38 +0100413$(LOCAL_BUILT_MODULE): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS)
Colin Cross8e404122014-02-06 14:45:37 -0800414$(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest)
415 @echo "target Package: $(PRIVATE_MODULE) ($@)"
Yohann Roussel37822c42015-01-09 10:36:40 +0100416ifdef LOCAL_JACK_ENABLED
Colin Cross8e404122014-02-06 14:45:37 -0800417 $(create-empty-package)
Ying Wang33360dd2015-01-14 14:23:56 -0800418else
419 $(if $(PRIVATE_SOURCE_ARCHIVE),\
420 $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@),\
421 $(create-empty-package))
422endif
Colin Cross8e404122014-02-06 14:45:37 -0800423 $(add-assets-to-package)
424ifneq ($(jni_shared_libraries),)
425 $(add-jni-shared-libs-to-package)
426endif
Ying Wang8b27d182015-03-27 11:07:17 -0700427ifeq ($(full_classes_jar),)
428# We don't build jar, need to add the Java resources here.
429 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
430else
Colin Cross8e404122014-02-06 14:45:37 -0800431 $(add-dex-to-package)
432endif
Yohann Roussel37822c42015-01-09 10:36:40 +0100433ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200434 $(add-carried-jack-resources)
435endif
Colin Cross8e404122014-02-06 14:45:37 -0800436ifdef LOCAL_DEX_PREOPT
Colin Cross8e404122014-02-06 14:45:37 -0800437ifneq (nostripping,$(LOCAL_DEX_PREOPT))
438 $(call dexpreopt-remove-classes.dex,$@)
439endif
440endif
Kenny Rootdff37552015-04-15 12:09:32 -0700441 $(sign-package)
Colin Cross8e404122014-02-06 14:45:37 -0800442 @# Alignment must happen after all other zip operations.
443 $(align-package)
444
Ying Wang36142f62014-05-21 16:13:33 -0700445###############################
Ying Wang8070b202014-12-01 17:46:56 -0800446## Build dpi-specific apks, if it's apps_only build.
447ifdef TARGET_BUILD_APPS
448ifdef LOCAL_DPI_VARIANTS
449$(foreach d, $(LOCAL_DPI_VARIANTS), \
450 $(eval my_dpi := $(d)) \
451 $(eval include $(BUILD_SYSTEM)/dpi_specific_apk.mk))
452endif
453endif
454
455###############################
Ying Wang36142f62014-05-21 16:13:33 -0700456## Rule to build the odex file
457ifdef LOCAL_DEX_PREOPT
458$(built_odex): PRIVATE_DEX_FILE := $(built_dex)
Ying Wangdb48da72014-09-13 11:26:39 -0700459# Use pattern rule - we may have multiple built odex files.
460$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(built_dex)
Ying Wang994c2262014-05-28 13:34:59 -0700461 $(hide) mkdir -p $(dir $@) && rm -f $@
Ying Wang36142f62014-05-21 16:13:33 -0700462 $(add-dex-to-package)
463 $(hide) mv $@ $@.input
464 $(call dexpreopt-one-file,$@.input,$@)
465 $(hide) rm $@.input
466endif
467
Ying Wang1425e2d2014-07-22 15:42:11 -0700468###############################
469## APK splits
470ifdef LOCAL_PACKAGE_SPLITS
Ying Wang7f625aa2014-07-23 10:27:57 -0700471# LOCAL_PACKAGE_SPLITS is a list of resource labels.
Ying Wang114a0fc2014-10-01 12:01:04 -0700472# aapt will convert comma inside resource lable to underscore in the file names.
473my_split_suffixes := $(subst $(comma),_,$(LOCAL_PACKAGE_SPLITS))
474built_apk_splits := $(foreach s,$(my_split_suffixes),$(built_module_path)/package_$(s).apk)
475installed_apk_splits := $(foreach s,$(my_split_suffixes),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Ying Wang1425e2d2014-07-22 15:42:11 -0700476
Ying Wang7f625aa2014-07-23 10:27:57 -0700477# The splits should have been built in the same command building the base apk.
478# This rule just runs signing and zipalign etc.
479# Note that we explicily check the existence of the split apk and remove the
480# built base apk if the split apk isn't there.
481# That way the build system will rerun the aapt after the user changes the splitting parameters.
Ying Wang1425e2d2014-07-22 15:42:11 -0700482$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
483$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
Ying Wang7f625aa2014-07-23 10:27:57 -0700484$(built_apk_splits) : $(built_module_path)/%.apk : $(LOCAL_BUILT_MODULE)
485 $(hide) if [ ! -f $@ ]; then \
486 echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \
487 rm $<; exit 1; \
488 fi
489 $(sign-package)
490 $(align-package)
Ying Wang1425e2d2014-07-22 15:42:11 -0700491
492# Rules to install the splits
Ying Wang7f625aa2014-07-23 10:27:57 -0700493$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(built_module_path)/package_%.apk | $(ACP)
494 @echo "Install: $@"
495 $(copy-file-to-new-target)
Ying Wang1425e2d2014-07-22 15:42:11 -0700496
497# Register the additional built and installed files.
498ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
499ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
Ying Wang114a0fc2014-10-01 12:01:04 -0700500 $(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 -0700501
502# Make sure to install the splits when you run "make <module_name>".
503$(my_register_name): $(installed_apk_splits)
504endif # LOCAL_PACKAGE_SPLITS
505
Colin Cross8e404122014-02-06 14:45:37 -0800506# Save information about this package
507PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
508PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
509ifdef package_resource_overlays
510PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_OVERLAYS := $(package_resource_overlays)
511endif
512
513PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
514
Colin Cross8e404122014-02-06 14:45:37 -0800515endif # skip_definition
516
517# Reset internal variables.
518all_res_assets :=