blob: e0df3255464d8ce4848ba9374a96c8da1173f498 [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 Rousselb4c49cb2014-09-08 14:45:14 +0200169ifndef LOCAL_JACK_PROGUARD_FLAGS
170 LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS)
171endif
172LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200173
Colin Cross8e404122014-02-06 14:45:37 -0800174ifeq (true,$(EMMA_INSTRUMENT))
175ifndef LOCAL_EMMA_INSTRUMENT
176# No emma for test apks.
Ying Wang324ffb22015-11-06 11:22:28 -0800177ifeq (,$(LOCAL_INSTRUMENTATION_FOR))
Colin Cross8e404122014-02-06 14:45:37 -0800178LOCAL_EMMA_INSTRUMENT := true
179endif # No test apk
180endif # LOCAL_EMMA_INSTRUMENT is not set
181else
182LOCAL_EMMA_INSTRUMENT := false
183endif # EMMA_INSTRUMENT is true
184
Ying Wang85865732016-03-28 18:39:42 -0700185ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),)
186# Only add jacocoagent if the package contains some java code
Colin Cross8e404122014-02-06 14:45:37 -0800187ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
188ifeq (true,$(EMMA_INSTRUMENT_STATIC))
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100189# Jack supports coverage with Jacoco
190LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
Ying Wang85865732016-03-28 18:39:42 -0700191else # ! EMMA_INSTRUMENT_STATIC
Colin Cross8e404122014-02-06 14:45:37 -0800192ifdef LOCAL_SDK_VERSION
193ifdef TARGET_BUILD_APPS
Sebastien Hertz2319e562016-03-31 16:48:26 +0200194# In unbundled build, merge the coverage library into the apk.
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100195# Jack supports coverage with Jacoco
196LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
Sebastien Hertz2319e562016-03-31 16:48:26 +0200197# Exclude jacoco classes from proguard
198LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
199LOCAL_JACK_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
200else # ! TARGET_BUILD_APPS
201# If build against the SDK in full build, core.jar is not used
202# so coverage classes are not present.
203# Jack needs jacoco on the classpath but we do not want it to be in
204# the final apk. While it is a static library, we add it to the
205# LOCAL_JAVA_LIBRARIES which are only present on the classpath.
206# Note: we have nothing to do for proguard since jacoco will be
207# on the classpath only, thus not modified during the compilation.
208LOCAL_JAVA_LIBRARIES += jacocoagent
Ying Wang85865732016-03-28 18:39:42 -0700209endif # TARGET_BUILD_APPS
Colin Cross8e404122014-02-06 14:45:37 -0800210endif # LOCAL_SDK_VERSION
Ying Wang85865732016-03-28 18:39:42 -0700211endif # ! EMMA_INSTRUMENT_STATIC
Colin Cross8e404122014-02-06 14:45:37 -0800212endif # LOCAL_EMMA_INSTRUMENT
Ying Wang85865732016-03-28 18:39:42 -0700213endif # Contains java code
Colin Cross8e404122014-02-06 14:45:37 -0800214
215rs_compatibility_jni_libs :=
216
Ying Wange9dd9f22014-10-29 15:48:32 -0700217include $(BUILD_SYSTEM)/android_manifest.mk
218
Colin Cross8e404122014-02-06 14:45:37 -0800219#################################
220include $(BUILD_SYSTEM)/java.mk
221#################################
222
223LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
224ifeq ($(LOCAL_SDK_RES_VERSION),)
225 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
226endif
227
Colin Cross8e404122014-02-06 14:45:37 -0800228$(LOCAL_INTERMEDIATE_TARGETS): \
229 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
Ying Wangefb93582014-07-19 17:00:50 -0700230ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION)))
Colin Cross8e404122014-02-06 14:45:37 -0800231$(LOCAL_INTERMEDIATE_TARGETS): \
232 PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION)
233else
234$(LOCAL_INTERMEDIATE_TARGETS): \
235 PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
236endif
237
Ying Wang61291922014-06-25 13:23:58 -0700238ifeq ($(need_compile_res),true)
Colin Cross8e404122014-02-06 14:45:37 -0800239
240# Since we don't know where the real R.java file is going to end up,
241# we need to use another file to stand in its place. We'll just
242# copy the generated file to src/R.stamp, which means it will
243# have the same contents and timestamp as the actual file.
244#
245# At the same time, this will copy the R.java file to a central
246# 'R' directory to make it easier to add the files to an IDE.
247#
Colin Cross8e404122014-02-06 14:45:37 -0800248
249$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
250 $(intermediates.COMMON)/public_resources.xml
251$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
252$(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT) | $(ACP)
253 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
Martin Arenlindfb6985e2015-09-15 15:52:56 +0200254 @rm -rf $@ && mkdir -p $(dir $@)
Colin Cross8e404122014-02-06 14:45:37 -0800255 $(create-resource-java-files)
256 $(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
257 -name Manifest.java 2> /dev/null`; do \
258 dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_MANIFEST_FILE`; \
259 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
260 $(ACP) -fp $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
261 done;
262 $(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
263 -name R.java 2> /dev/null`; do \
264 dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_R_FILE`; \
265 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
266 $(ACP) -fp $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
267 || exit 31; \
268 $(ACP) -fp $$GENERATED_R_FILE $@ || exit 32; \
Martin Arenlindfb6985e2015-09-15 15:52:56 +0200269 done;
270 @# Ensure that the target file is always created, i.e. also in case we did not
271 @# enter the GENERATED_R_FILE-loop above. This avoids unnecessary rebuilding.
272 $(hide) touch $@
Colin Cross8e404122014-02-06 14:45:37 -0800273
274$(proguard_options_file): $(R_file_stamp)
275
Ying Wangdbe23f52014-03-25 14:42:46 -0700276resource_export_package :=
Colin Cross8e404122014-02-06 14:45:37 -0800277ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
278# Put this module's resources into a PRODUCT-agnositc package that
279# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
280# files.
281resource_export_package := $(intermediates.COMMON)/package-export.apk
282$(R_file_stamp): $(resource_export_package)
283
284# add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
285# can't know anything about PRODUCT. Clear it out just for this target.
286$(resource_export_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
287$(resource_export_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
288$(resource_export_package): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT)
289 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
290 $(create-empty-package)
291 $(add-assets-to-package)
292endif
293
Ying Wang85865732016-03-28 18:39:42 -0700294# Make sure to generate R.java before compiling.
Colin Cross8e404122014-02-06 14:45:37 -0800295# Other modules should depend on the BUILT module if
296# they want to use this module's R.java file.
Ying Wang85865732016-03-28 18:39:42 -0700297$(LOCAL_BUILT_MODULE) \
298$(full_classes_compiled_jar) \
299$(built_dex_intermediate) $(noshrob_classes_jack) $(full_classes_jack) $(jack_check_timestamp) \
300 : $(R_file_stamp)
Colin Cross8e404122014-02-06 14:45:37 -0800301
Ying Wang61291922014-06-25 13:23:58 -0700302endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800303
304ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
305# We need to explicitly clear this var so that we don't
306# inherit the value from whomever caused us to be built.
307$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
308else
309# Most packages should link against the resources defined by framework-res.
310# Even if they don't have their own resources, they may use framework
311# resources.
Ying Wangefb93582014-07-19 17:00:50 -0700312ifneq ($(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 -0800313# for released sdk versions, the platform resources were built into android.jar.
314framework_res_package_export := \
315 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
316framework_res_package_export_deps := $(framework_res_package_export)
317else # LOCAL_SDK_RES_VERSION
318framework_res_package_export := \
319 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
320# We can't depend directly on the export.apk file; it won't get its
321# PRIVATE_ vars set up correctly if we do. Instead, depend on the
322# corresponding R.stamp file, which lists the export.apk as a dependency.
323framework_res_package_export_deps := \
324 $(dir $(framework_res_package_export))src/R.stamp
325endif # LOCAL_SDK_RES_VERSION
Adam Lesinskide057c32014-03-13 18:48:27 -0700326all_library_res_package_exports := \
327 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700328 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700329 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk)
330
331all_library_res_package_export_deps := \
332 $(framework_res_package_export_deps) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700333 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700334 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp)
335
Ying Wangb5745642014-06-19 16:07:30 -0700336$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps)
Colin Cross8e404122014-02-06 14:45:37 -0800337$(LOCAL_INTERMEDIATE_TARGETS): \
Adam Lesinskide057c32014-03-13 18:48:27 -0700338 PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports)
Colin Cross8e404122014-02-06 14:45:37 -0800339endif # LOCAL_NO_STANDARD_LIBRARIES
340
341ifneq ($(full_classes_jar),)
342$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
343$(LOCAL_BUILT_MODULE): $(built_dex)
Ying Wang33360dd2015-01-14 14:23:56 -0800344else
345$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE :=
Colin Cross8e404122014-02-06 14:45:37 -0800346endif # full_classes_jar
347
Ying Wang96bcad42014-04-17 13:38:04 -0700348include $(BUILD_SYSTEM)/install_jni_libs.mk
Colin Cross8e404122014-02-06 14:45:37 -0800349
350# Pick a key to sign the package with. If this package hasn't specified
351# an explicit certificate, use the default.
352# Secure release builds will have their packages signed after the fact,
353# so it's ok for these private keys to be in the clear.
354ifeq ($(LOCAL_CERTIFICATE),)
355 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
356endif
357
358ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
359 # The special value "EXTERNAL" means that we will sign it with the
360 # default devkey, apply predexopt, but then expect the final .apk
361 # (after dexopting) to be signed by an outside tool.
362 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
363 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
364endif
365
366# If this is not an absolute certificate, assign it to a generic one.
367ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
368 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
369endif
370private_key := $(LOCAL_CERTIFICATE).pk8
371certificate := $(LOCAL_CERTIFICATE).x509.pem
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900372additional_certificates := $(foreach c,$(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
Colin Cross8e404122014-02-06 14:45:37 -0800373
374$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
375$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
376$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
377
378PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
379PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
380
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900381$(LOCAL_BUILT_MODULE): $(additional_certificates)
382$(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(additional_certificates)
Colin Cross8e404122014-02-06 14:45:37 -0800383
384# Define the rule to build the actual package.
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800385$(LOCAL_BUILT_MODULE): $(AAPT)
Ying Wang8e20ef62014-06-24 20:01:52 -0700386# PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>.
387$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
388# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
389$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
Colin Cross8e404122014-02-06 14:45:37 -0800390ifneq ($(TARGET_BUILD_APPS),)
391 # Include all resources for unbundled apps.
392 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
393endif
394ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
395 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG :=
396 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
397else
398 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG)
Ying Wang934008f2014-07-30 13:40:14 -0700399ifdef LOCAL_PACKAGE_SPLITS
400 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
401else
Colin Cross8e404122014-02-06 14:45:37 -0800402 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG)
403endif
Ying Wang934008f2014-07-30 13:40:14 -0700404endif
Colin Cross8e404122014-02-06 14:45:37 -0800405$(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest)
406 @echo "target Package: $(PRIVATE_MODULE) ($@)"
407 $(create-empty-package)
408 $(add-assets-to-package)
409ifneq ($(jni_shared_libraries),)
410 $(add-jni-shared-libs-to-package)
411endif
Ying Wang8b27d182015-03-27 11:07:17 -0700412ifeq ($(full_classes_jar),)
413# We don't build jar, need to add the Java resources here.
414 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800415else # full_classes_jar
Colin Cross8e404122014-02-06 14:45:37 -0800416 $(add-dex-to-package)
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800417endif # full_classes_jar
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200418 $(add-carried-jack-resources)
Colin Cross8e404122014-02-06 14:45:37 -0800419ifdef LOCAL_DEX_PREOPT
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800420ifneq ($(BUILD_PLATFORM_ZIP),)
421 @# Keep a copy of apk with classes.dex unstripped
422 $(hide) cp -f $@ $(dir $@)package.dex.apk
423endif # BUILD_PLATFORM_ZIP
Colin Cross8e404122014-02-06 14:45:37 -0800424ifneq (nostripping,$(LOCAL_DEX_PREOPT))
425 $(call dexpreopt-remove-classes.dex,$@)
426endif
427endif
Kenny Rootdff37552015-04-15 12:09:32 -0700428 $(sign-package)
Colin Cross8e404122014-02-06 14:45:37 -0800429
Ying Wang36142f62014-05-21 16:13:33 -0700430###############################
Ying Wang8070b202014-12-01 17:46:56 -0800431## Build dpi-specific apks, if it's apps_only build.
432ifdef TARGET_BUILD_APPS
433ifdef LOCAL_DPI_VARIANTS
434$(foreach d, $(LOCAL_DPI_VARIANTS), \
435 $(eval my_dpi := $(d)) \
436 $(eval include $(BUILD_SYSTEM)/dpi_specific_apk.mk))
437endif
438endif
439
440###############################
Ying Wang36142f62014-05-21 16:13:33 -0700441## Rule to build the odex file
442ifdef LOCAL_DEX_PREOPT
443$(built_odex): PRIVATE_DEX_FILE := $(built_dex)
Ying Wangdb48da72014-09-13 11:26:39 -0700444# Use pattern rule - we may have multiple built odex files.
445$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(built_dex)
Ying Wang994c2262014-05-28 13:34:59 -0700446 $(hide) mkdir -p $(dir $@) && rm -f $@
Ying Wang36142f62014-05-21 16:13:33 -0700447 $(add-dex-to-package)
448 $(hide) mv $@ $@.input
449 $(call dexpreopt-one-file,$@.input,$@)
450 $(hide) rm $@.input
451endif
452
Ying Wang1425e2d2014-07-22 15:42:11 -0700453###############################
454## APK splits
455ifdef LOCAL_PACKAGE_SPLITS
Ying Wang7f625aa2014-07-23 10:27:57 -0700456# LOCAL_PACKAGE_SPLITS is a list of resource labels.
Ying Wang114a0fc2014-10-01 12:01:04 -0700457# aapt will convert comma inside resource lable to underscore in the file names.
458my_split_suffixes := $(subst $(comma),_,$(LOCAL_PACKAGE_SPLITS))
459built_apk_splits := $(foreach s,$(my_split_suffixes),$(built_module_path)/package_$(s).apk)
460installed_apk_splits := $(foreach s,$(my_split_suffixes),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Ying Wang1425e2d2014-07-22 15:42:11 -0700461
Ying Wang7f625aa2014-07-23 10:27:57 -0700462# The splits should have been built in the same command building the base apk.
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800463# This rule just runs signing.
Ying Wang7f625aa2014-07-23 10:27:57 -0700464# Note that we explicily check the existence of the split apk and remove the
465# built base apk if the split apk isn't there.
466# That way the build system will rerun the aapt after the user changes the splitting parameters.
Ying Wang1425e2d2014-07-22 15:42:11 -0700467$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
468$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
Ying Wang7f625aa2014-07-23 10:27:57 -0700469$(built_apk_splits) : $(built_module_path)/%.apk : $(LOCAL_BUILT_MODULE)
470 $(hide) if [ ! -f $@ ]; then \
471 echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \
472 rm $<; exit 1; \
473 fi
474 $(sign-package)
Ying Wang1425e2d2014-07-22 15:42:11 -0700475
476# Rules to install the splits
Dan Willemsen7f016152016-02-29 17:52:39 -0800477$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(built_module_path)/package_%.apk
Ying Wang7f625aa2014-07-23 10:27:57 -0700478 @echo "Install: $@"
479 $(copy-file-to-new-target)
Ying Wang1425e2d2014-07-22 15:42:11 -0700480
481# Register the additional built and installed files.
482ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
483ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
Ying Wang114a0fc2014-10-01 12:01:04 -0700484 $(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 -0700485
486# Make sure to install the splits when you run "make <module_name>".
487$(my_register_name): $(installed_apk_splits)
488endif # LOCAL_PACKAGE_SPLITS
489
Colin Cross8e404122014-02-06 14:45:37 -0800490# Save information about this package
491PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
492PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
493ifdef package_resource_overlays
494PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_OVERLAYS := $(package_resource_overlays)
495endif
496
497PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
498
Colin Cross8e404122014-02-06 14:45:37 -0800499endif # skip_definition
500
501# Reset internal variables.
502all_res_assets :=