blob: fd92d01da855d35281e0d6ced4933305cc94fa2d [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
60# Package LOCAL_MODULE_TAGS default to optional
61LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
62ifeq ($(LOCAL_MODULE_TAGS),)
63LOCAL_MODULE_TAGS := optional
64endif
65
66ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),)
67# Force localization check if it's not tagged as tests.
68LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z
69endif
70
Ying Wang1425e2d2014-07-22 15:42:11 -070071ifdef LOCAL_PACKAGE_SPLITS
72LOCAL_AAPT_FLAGS += $(addprefix --split ,$(LOCAL_PACKAGE_SPLITS))
73endif
74
Ying Wangbfcdf062014-07-29 10:34:30 -070075need_compile_asset :=
Colin Cross8e404122014-02-06 14:45:37 -080076ifeq (,$(LOCAL_ASSET_DIR))
77LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
Ying Wangbfcdf062014-07-29 10:34:30 -070078else
79need_compile_asset := true
Colin Cross8e404122014-02-06 14:45:37 -080080endif
81
Ying Wang61291922014-06-25 13:23:58 -070082# LOCAL_RESOURCE_DIR may point to resource generated during the build
83need_compile_res :=
Colin Cross8e404122014-02-06 14:45:37 -080084ifeq (,$(LOCAL_RESOURCE_DIR))
85 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
Ying Wang61291922014-06-25 13:23:58 -070086else
87 need_compile_res := true
Colin Cross8e404122014-02-06 14:45:37 -080088endif
89
90package_resource_overlays := $(strip \
91 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
92 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
93 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
94 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))))
95
96LOCAL_RESOURCE_DIR := $(package_resource_overlays) $(LOCAL_RESOURCE_DIR)
97
Colin Cross2c321442014-02-12 13:06:30 -080098all_assets := $(strip \
99 $(foreach dir, $(LOCAL_ASSET_DIR), \
100 $(addprefix $(dir)/, \
101 $(patsubst assets/%,%, \
102 $(call find-subdir-assets, $(dir)) \
103 ) \
104 ) \
105 ))
Colin Cross8e404122014-02-06 14:45:37 -0800106
Ying Wangbfcdf062014-07-29 10:34:30 -0700107ifneq ($(all_assets),)
108need_compile_asset := true
109endif
110
Colin Cross8e404122014-02-06 14:45:37 -0800111all_resources := $(strip \
112 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
113 $(addprefix $(dir)/, \
114 $(patsubst res/%,%, \
115 $(call find-subdir-assets,$(dir)) \
116 ) \
117 ) \
118 ))
119
Ying Wang61291922014-06-25 13:23:58 -0700120ifneq ($(all_resources),)
121 need_compile_res := true
122endif
123
Colin Cross8e404122014-02-06 14:45:37 -0800124all_res_assets := $(strip $(all_assets) $(all_resources))
125
126package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
127# If no assets or resources were found, clear the directory variables so
128# we don't try to build them.
Ying Wangbfcdf062014-07-29 10:34:30 -0700129ifneq (true,$(need_compile_asset))
Colin Cross8e404122014-02-06 14:45:37 -0800130LOCAL_ASSET_DIR:=
131endif
Ying Wang61291922014-06-25 13:23:58 -0700132ifneq (true,$(need_compile_res))
Colin Cross8e404122014-02-06 14:45:37 -0800133LOCAL_RESOURCE_DIR:=
134R_file_stamp :=
135else
136# Make sure that R_file_stamp inherits the proper PRIVATE vars.
137# If R.stamp moves, be sure to update the framework makefile,
138# which has intimate knowledge of its location.
139R_file_stamp := $(package_expected_intermediates_COMMON)/src/R.stamp
140LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
141endif
142
143LOCAL_BUILT_MODULE_STEM := package.apk
Ying Wangaf9757e2014-07-17 21:24:42 -0700144LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
Colin Cross8e404122014-02-06 14:45:37 -0800145
146LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
147ifndef LOCAL_PROGUARD_ENABLED
148ifneq ($(DISABLE_PROGUARD),true)
149 LOCAL_PROGUARD_ENABLED :=full
150endif
151endif
152ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
153 # the package explicitly request to disable proguard.
154 LOCAL_PROGUARD_ENABLED :=
155endif
156proguard_options_file :=
157ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
Ying Wang61291922014-06-25 13:23:58 -0700158ifeq ($(need_compile_res),true)
Colin Cross8e404122014-02-06 14:45:37 -0800159 proguard_options_file := $(package_expected_intermediates_COMMON)/proguard_options
Ying Wang61291922014-06-25 13:23:58 -0700160endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800161endif # !custom
162LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
163
164ifeq (true,$(EMMA_INSTRUMENT))
165ifndef LOCAL_EMMA_INSTRUMENT
166# No emma for test apks.
167ifeq (,$(filer tests,$(LOCAL_MODULE_TAGS))$(LOCAL_INSTRUMENTATION_FOR))
168LOCAL_EMMA_INSTRUMENT := true
169endif # No test apk
170endif # LOCAL_EMMA_INSTRUMENT is not set
171else
172LOCAL_EMMA_INSTRUMENT := false
173endif # EMMA_INSTRUMENT is true
174
175ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
176ifeq (true,$(EMMA_INSTRUMENT_STATIC))
177LOCAL_STATIC_JAVA_LIBRARIES += emma
178else
179ifdef LOCAL_SDK_VERSION
180ifdef TARGET_BUILD_APPS
181# In unbundled build merge the emma library into the apk.
182LOCAL_STATIC_JAVA_LIBRARIES += emma
183else
184# If build against the SDK in full build, core.jar is not used,
185# we have to use prebiult emma.jar to make Proguard happy;
186# Otherwise emma classes are included in core.jar.
187LOCAL_PROGUARD_FLAGS += -libraryjars $(EMMA_JAR)
188endif # full build
189endif # LOCAL_SDK_VERSION
190endif # EMMA_INSTRUMENT_STATIC
191endif # LOCAL_EMMA_INSTRUMENT
192
193rs_compatibility_jni_libs :=
194
195#################################
196include $(BUILD_SYSTEM)/java.mk
197#################################
198
199LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
200ifeq ($(LOCAL_SDK_RES_VERSION),)
201 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
202endif
203
Colin Cross2c321442014-02-12 13:06:30 -0800204include $(BUILD_SYSTEM)/android_manifest.mk
205
Colin Cross8e404122014-02-06 14:45:37 -0800206$(LOCAL_INTERMEDIATE_TARGETS): \
207 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
Ying Wangefb93582014-07-19 17:00:50 -0700208ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION)))
Colin Cross8e404122014-02-06 14:45:37 -0800209$(LOCAL_INTERMEDIATE_TARGETS): \
210 PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION)
211else
212$(LOCAL_INTERMEDIATE_TARGETS): \
213 PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
214endif
215
Ying Wang61291922014-06-25 13:23:58 -0700216ifeq ($(need_compile_res),true)
Colin Cross8e404122014-02-06 14:45:37 -0800217
218# Since we don't know where the real R.java file is going to end up,
219# we need to use another file to stand in its place. We'll just
220# copy the generated file to src/R.stamp, which means it will
221# have the same contents and timestamp as the actual file.
222#
223# At the same time, this will copy the R.java file to a central
224# 'R' directory to make it easier to add the files to an IDE.
225#
226#TODO: use PRIVATE_SOURCE_INTERMEDIATES_DIR instead of
227# $(intermediates.COMMON)/src
228ifneq ($(package_expected_intermediates_COMMON),$(intermediates.COMMON))
229 $(error $(LOCAL_MODULE): internal error: expected intermediates.COMMON "$(package_expected_intermediates_COMMON)" != intermediates.COMMON "$(intermediates.COMMON)")
230endif
231
232$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
233 $(intermediates.COMMON)/public_resources.xml
234$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
235$(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT) | $(ACP)
236 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
237 @rm -f $@
238 $(create-resource-java-files)
239 $(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
240 -name Manifest.java 2> /dev/null`; do \
241 dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_MANIFEST_FILE`; \
242 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
243 $(ACP) -fp $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
244 done;
245 $(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
246 -name R.java 2> /dev/null`; do \
247 dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_R_FILE`; \
248 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
249 $(ACP) -fp $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
250 || exit 31; \
251 $(ACP) -fp $$GENERATED_R_FILE $@ || exit 32; \
252 done; \
253
254$(proguard_options_file): $(R_file_stamp)
255
Ying Wangdbe23f52014-03-25 14:42:46 -0700256resource_export_package :=
Colin Cross8e404122014-02-06 14:45:37 -0800257ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
258# Put this module's resources into a PRODUCT-agnositc package that
259# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
260# files.
261resource_export_package := $(intermediates.COMMON)/package-export.apk
262$(R_file_stamp): $(resource_export_package)
263
264# add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
265# can't know anything about PRODUCT. Clear it out just for this target.
266$(resource_export_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
267$(resource_export_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
268$(resource_export_package): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT)
269 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
270 $(create-empty-package)
271 $(add-assets-to-package)
272endif
273
274# Other modules should depend on the BUILT module if
275# they want to use this module's R.java file.
276$(LOCAL_BUILT_MODULE): $(R_file_stamp)
277
278ifneq ($(full_classes_jar),)
279# If full_classes_jar is non-empty, we're building sources.
280# If we're building sources, the initial javac step (which
281# produces full_classes_compiled_jar) needs to ensure the
282# R.java and Manifest.java files have been generated first.
283$(full_classes_compiled_jar): $(R_file_stamp)
284endif
285
Ying Wang61291922014-06-25 13:23:58 -0700286endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800287
288ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
289# We need to explicitly clear this var so that we don't
290# inherit the value from whomever caused us to be built.
291$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
292else
293# Most packages should link against the resources defined by framework-res.
294# Even if they don't have their own resources, they may use framework
295# resources.
Ying Wangefb93582014-07-19 17:00:50 -0700296ifneq ($(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 -0800297# for released sdk versions, the platform resources were built into android.jar.
298framework_res_package_export := \
299 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
300framework_res_package_export_deps := $(framework_res_package_export)
301else # LOCAL_SDK_RES_VERSION
302framework_res_package_export := \
303 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
304# We can't depend directly on the export.apk file; it won't get its
305# PRIVATE_ vars set up correctly if we do. Instead, depend on the
306# corresponding R.stamp file, which lists the export.apk as a dependency.
307framework_res_package_export_deps := \
308 $(dir $(framework_res_package_export))src/R.stamp
309endif # LOCAL_SDK_RES_VERSION
Adam Lesinskide057c32014-03-13 18:48:27 -0700310all_library_res_package_exports := \
311 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700312 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700313 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk)
314
315all_library_res_package_export_deps := \
316 $(framework_res_package_export_deps) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700317 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700318 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp)
319
Ying Wangb5745642014-06-19 16:07:30 -0700320$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps)
Colin Cross8e404122014-02-06 14:45:37 -0800321$(LOCAL_INTERMEDIATE_TARGETS): \
Adam Lesinskide057c32014-03-13 18:48:27 -0700322 PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports)
Colin Cross8e404122014-02-06 14:45:37 -0800323endif # LOCAL_NO_STANDARD_LIBRARIES
324
325ifneq ($(full_classes_jar),)
326$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
327$(LOCAL_BUILT_MODULE): $(built_dex)
328endif # full_classes_jar
329
Ying Wang96bcad42014-04-17 13:38:04 -0700330include $(BUILD_SYSTEM)/install_jni_libs.mk
Colin Cross8e404122014-02-06 14:45:37 -0800331
332# Pick a key to sign the package with. If this package hasn't specified
333# an explicit certificate, use the default.
334# Secure release builds will have their packages signed after the fact,
335# so it's ok for these private keys to be in the clear.
336ifeq ($(LOCAL_CERTIFICATE),)
337 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
338endif
339
340ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
341 # The special value "EXTERNAL" means that we will sign it with the
342 # default devkey, apply predexopt, but then expect the final .apk
343 # (after dexopting) to be signed by an outside tool.
344 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
345 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
346endif
347
348# If this is not an absolute certificate, assign it to a generic one.
349ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
350 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
351endif
352private_key := $(LOCAL_CERTIFICATE).pk8
353certificate := $(LOCAL_CERTIFICATE).x509.pem
354
355$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
356$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
357$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
358
359PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
360PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
361
362$(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(foreach c,\
363 $(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
364
365# Define the rule to build the actual package.
366$(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN)
Ying Wang8e20ef62014-06-24 20:01:52 -0700367# PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>.
368$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
369# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
370$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
Colin Cross8e404122014-02-06 14:45:37 -0800371ifneq ($(TARGET_BUILD_APPS),)
372 # Include all resources for unbundled apps.
373 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
374endif
375ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
376 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG :=
377 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
378else
379 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG)
Ying Wang934008f2014-07-30 13:40:14 -0700380ifdef LOCAL_PACKAGE_SPLITS
381 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
382else
Colin Cross8e404122014-02-06 14:45:37 -0800383 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG)
384endif
Ying Wang934008f2014-07-30 13:40:14 -0700385endif
Colin Cross8e404122014-02-06 14:45:37 -0800386$(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest)
387 @echo "target Package: $(PRIVATE_MODULE) ($@)"
388 $(create-empty-package)
389 $(add-assets-to-package)
390ifneq ($(jni_shared_libraries),)
391 $(add-jni-shared-libs-to-package)
392endif
393ifneq ($(full_classes_jar),)
394 $(add-dex-to-package)
395endif
396 $(add-carried-java-resources)
397ifneq ($(extra_jar_args),)
398 $(add-java-resources-to-package)
399endif
400 $(sign-package)
401ifdef LOCAL_DEX_PREOPT
Colin Cross8e404122014-02-06 14:45:37 -0800402ifneq (nostripping,$(LOCAL_DEX_PREOPT))
403 $(call dexpreopt-remove-classes.dex,$@)
404endif
405endif
406 @# Alignment must happen after all other zip operations.
407 $(align-package)
408
Ying Wang36142f62014-05-21 16:13:33 -0700409###############################
410## Rule to build the odex file
411ifdef LOCAL_DEX_PREOPT
412$(built_odex): PRIVATE_DEX_FILE := $(built_dex)
413$(built_odex) : $(built_dex)
Ying Wang994c2262014-05-28 13:34:59 -0700414 $(hide) mkdir -p $(dir $@) && rm -f $@
Ying Wang36142f62014-05-21 16:13:33 -0700415 $(add-dex-to-package)
416 $(hide) mv $@ $@.input
417 $(call dexpreopt-one-file,$@.input,$@)
418 $(hide) rm $@.input
419endif
420
Ying Wang1425e2d2014-07-22 15:42:11 -0700421###############################
422## APK splits
423ifdef LOCAL_PACKAGE_SPLITS
Ying Wang7f625aa2014-07-23 10:27:57 -0700424# LOCAL_PACKAGE_SPLITS is a list of resource labels.
Ying Wang1425e2d2014-07-22 15:42:11 -0700425built_apk_splits := $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(built_module_path)/package_$(s).apk)
426installed_apk_splits := $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
427
Ying Wang7f625aa2014-07-23 10:27:57 -0700428# The splits should have been built in the same command building the base apk.
429# This rule just runs signing and zipalign etc.
430# Note that we explicily check the existence of the split apk and remove the
431# built base apk if the split apk isn't there.
432# That way the build system will rerun the aapt after the user changes the splitting parameters.
Ying Wang1425e2d2014-07-22 15:42:11 -0700433$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
434$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
Ying Wang7f625aa2014-07-23 10:27:57 -0700435$(built_apk_splits) : $(built_module_path)/%.apk : $(LOCAL_BUILT_MODULE)
436 $(hide) if [ ! -f $@ ]; then \
437 echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \
438 rm $<; exit 1; \
439 fi
440 $(sign-package)
441 $(align-package)
Ying Wang1425e2d2014-07-22 15:42:11 -0700442
443# Rules to install the splits
Ying Wang7f625aa2014-07-23 10:27:57 -0700444$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(built_module_path)/package_%.apk | $(ACP)
445 @echo "Install: $@"
446 $(copy-file-to-new-target)
Ying Wang1425e2d2014-07-22 15:42:11 -0700447
448# Register the additional built and installed files.
449ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
450ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
451 $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(built_module_path)/package_$(s).apk:$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
452
453# Make sure to install the splits when you run "make <module_name>".
454$(my_register_name): $(installed_apk_splits)
455endif # LOCAL_PACKAGE_SPLITS
456
Colin Cross8e404122014-02-06 14:45:37 -0800457# Save information about this package
458PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
459PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
460ifdef package_resource_overlays
461PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_OVERLAYS := $(package_resource_overlays)
462endif
463
464PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
465
466# Dist the files that can be bundled in system.img.
467# They include the jni shared libraries and the apk with jni libraries stripped.
468ifeq ($(LOCAL_DIST_BUNDLED_BINARIES),true)
469ifneq ($(filter $(LOCAL_PACKAGE_NAME),$(TARGET_BUILD_APPS)),)
470ifneq ($(strip $(jni_shared_libraries)),)
471dist_subdir := bundled_$(LOCAL_PACKAGE_NAME)
472$(foreach f, $(jni_shared_libraries), \
473 $(call dist-for-goals, apps_only, $(f):$(dist_subdir)/$(notdir $(f))))
474
475apk_jni_stripped := $(intermediates)/jni_stripped/package.apk
476$(apk_jni_stripped): PRIVATE_JNI_SHARED_LIBRARIES := $(notdir $(jni_shared_libraries))
477$(apk_jni_stripped) : $(LOCAL_BUILT_MODULE) | $(ZIPALIGN)
478 @rm -rf $(dir $@) && mkdir -p $(dir $@)
479 $(hide) cp $< $@
480 $(hide) zip -d $@ $(foreach f,$(PRIVATE_JNI_SHARED_LIBRARIES),\*/$(f))
481 $(call align-package)
482
483$(call dist-for-goals, apps_only, $(apk_jni_stripped):$(dist_subdir)/$(LOCAL_PACKAGE_NAME).apk)
484
485endif # jni_shared_libraries
486endif # apps_only build
487endif # LOCAL_DIST_BUNDLED_BINARIES
488
489# Lint phony targets
490.PHONY: lint-$(LOCAL_PACKAGE_NAME)
491lint-$(LOCAL_PACKAGE_NAME): PRIVATE_PATH := $(LOCAL_PATH)
492lint-$(LOCAL_PACKAGE_NAME): PRIVATE_LINT_FLAGS := $(LOCAL_LINT_FLAGS)
493lint-$(LOCAL_PACKAGE_NAME) :
494 @echo lint $(PRIVATE_PATH)
495 $(LINT) $(PRIVATE_LINT_FLAGS) $(PRIVATE_PATH)
496
497lintall : lint-$(LOCAL_PACKAGE_NAME)
498
499endif # skip_definition
500
501# Reset internal variables.
502all_res_assets :=