blob: 30022bce791a296f4835f3f39fb04acf6d191010 [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 Wang1425e2d2014-07-22 15:42:11 -070078ifdef LOCAL_PACKAGE_SPLITS
79LOCAL_AAPT_FLAGS += $(addprefix --split ,$(LOCAL_PACKAGE_SPLITS))
80endif
81
Ying Wang4cb04992014-07-29 10:34:30 -070082need_compile_asset :=
Colin Cross8e404122014-02-06 14:45:37 -080083ifeq (,$(LOCAL_ASSET_DIR))
84LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
Ying Wang4cb04992014-07-29 10:34:30 -070085else
86need_compile_asset := true
Colin Cross8e404122014-02-06 14:45:37 -080087endif
88
Ying Wang61291922014-06-25 13:23:58 -070089# LOCAL_RESOURCE_DIR may point to resource generated during the build
90need_compile_res :=
Colin Cross8e404122014-02-06 14:45:37 -080091ifeq (,$(LOCAL_RESOURCE_DIR))
92 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
Ying Wang61291922014-06-25 13:23:58 -070093else
94 need_compile_res := true
Colin Cross8e404122014-02-06 14:45:37 -080095endif
96
97package_resource_overlays := $(strip \
98 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
99 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
100 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
101 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))))
102
103LOCAL_RESOURCE_DIR := $(package_resource_overlays) $(LOCAL_RESOURCE_DIR)
104
Colin Cross2c321442014-02-12 13:06:30 -0800105all_assets := $(strip \
106 $(foreach dir, $(LOCAL_ASSET_DIR), \
107 $(addprefix $(dir)/, \
108 $(patsubst assets/%,%, \
109 $(call find-subdir-assets, $(dir)) \
110 ) \
111 ) \
112 ))
Colin Cross8e404122014-02-06 14:45:37 -0800113
Ying Wang4cb04992014-07-29 10:34:30 -0700114ifneq ($(all_assets),)
115need_compile_asset := true
116endif
117
Ying Wangdd71c852015-12-04 13:59:18 -0800118ifdef USE_AAPT2
119# In aapt2 the last takes precedence.
120my_resource_dirs := $(call reverse-list,$(LOCAL_RESOURCE_DIR))
121my_res_resources :=
122my_overlay_resources :=
123# Treat all but the first directory as overlays.
124my_overlay_resources := $(strip \
125 $(foreach d,$(wordlist 2,999,$(my_resource_dirs)),\
126 $(addprefix $(d)/, \
127 $(call find-subdir-assets,$(d)))))
128
129my_res_dir := $(firstword $(my_resource_dirs))
130my_res_resources := $(strip \
131 $(addprefix $(my_res_dir)/, \
132 $(call find-subdir-assets,$(my_res_dir))))
133
134all_resources := $(strip $(my_res_resources) $(my_overlay_resources))
135
136# The linked resource package.
137my_res_package := $(intermediates)/package-res.apk
138LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
139
140# Always run aapt2
141need_compile_res := true
142
143else # USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800144all_resources := $(strip \
145 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
146 $(addprefix $(dir)/, \
147 $(patsubst res/%,%, \
148 $(call find-subdir-assets,$(dir)) \
149 ) \
150 ) \
151 ))
152
Ying Wangdd71c852015-12-04 13:59:18 -0800153endif # USE_AAPT2
154
Ying Wang61291922014-06-25 13:23:58 -0700155ifneq ($(all_resources),)
156 need_compile_res := true
157endif
158
Colin Cross8e404122014-02-06 14:45:37 -0800159all_res_assets := $(strip $(all_assets) $(all_resources))
160
Ying Wang98ae7982014-12-18 14:53:52 -0800161
Colin Cross8e404122014-02-06 14:45:37 -0800162# If no assets or resources were found, clear the directory variables so
163# we don't try to build them.
Ying Wang4cb04992014-07-29 10:34:30 -0700164ifneq (true,$(need_compile_asset))
Colin Cross8e404122014-02-06 14:45:37 -0800165LOCAL_ASSET_DIR:=
166endif
Ying Wang61291922014-06-25 13:23:58 -0700167ifneq (true,$(need_compile_res))
Colin Cross8e404122014-02-06 14:45:37 -0800168LOCAL_RESOURCE_DIR:=
169R_file_stamp :=
170else
171# Make sure that R_file_stamp inherits the proper PRIVATE vars.
172# If R.stamp moves, be sure to update the framework makefile,
173# which has intimate knowledge of its location.
Ying Wang98ae7982014-12-18 14:53:52 -0800174R_file_stamp := $(intermediates.COMMON)/src/R.stamp
Colin Cross8e404122014-02-06 14:45:37 -0800175LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
176endif
177
178LOCAL_BUILT_MODULE_STEM := package.apk
Ying Wangaf9757e2014-07-17 21:24:42 -0700179LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
Colin Cross8e404122014-02-06 14:45:37 -0800180
181LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
182ifndef LOCAL_PROGUARD_ENABLED
183ifneq ($(DISABLE_PROGUARD),true)
184 LOCAL_PROGUARD_ENABLED :=full
185endif
186endif
187ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
188 # the package explicitly request to disable proguard.
189 LOCAL_PROGUARD_ENABLED :=
190endif
191proguard_options_file :=
192ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
Ying Wang61291922014-06-25 13:23:58 -0700193ifeq ($(need_compile_res),true)
Ying Wang98ae7982014-12-18 14:53:52 -0800194 proguard_options_file := $(intermediates.COMMON)/proguard_options
Ying Wang61291922014-06-25 13:23:58 -0700195endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800196endif # !custom
197LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
198
Yohann Roussel37822c42015-01-09 10:36:40 +0100199ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200200ifndef LOCAL_JACK_PROGUARD_FLAGS
201 LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS)
202endif
203LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS)
Yohann Roussel37822c42015-01-09 10:36:40 +0100204endif # LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200205
Colin Cross8e404122014-02-06 14:45:37 -0800206ifeq (true,$(EMMA_INSTRUMENT))
207ifndef LOCAL_EMMA_INSTRUMENT
208# No emma for test apks.
Ying Wang324ffb22015-11-06 11:22:28 -0800209ifeq (,$(LOCAL_INSTRUMENTATION_FOR))
Colin Cross8e404122014-02-06 14:45:37 -0800210LOCAL_EMMA_INSTRUMENT := true
211endif # No test apk
212endif # LOCAL_EMMA_INSTRUMENT is not set
213else
214LOCAL_EMMA_INSTRUMENT := false
215endif # EMMA_INSTRUMENT is true
216
217ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
218ifeq (true,$(EMMA_INSTRUMENT_STATIC))
219LOCAL_STATIC_JAVA_LIBRARIES += emma
220else
221ifdef LOCAL_SDK_VERSION
222ifdef TARGET_BUILD_APPS
223# In unbundled build merge the emma library into the apk.
224LOCAL_STATIC_JAVA_LIBRARIES += emma
225else
226# If build against the SDK in full build, core.jar is not used,
227# we have to use prebiult emma.jar to make Proguard happy;
228# Otherwise emma classes are included in core.jar.
229LOCAL_PROGUARD_FLAGS += -libraryjars $(EMMA_JAR)
230endif # full build
231endif # LOCAL_SDK_VERSION
232endif # EMMA_INSTRUMENT_STATIC
233endif # LOCAL_EMMA_INSTRUMENT
234
235rs_compatibility_jni_libs :=
236
Ying Wanged0361f2015-04-19 09:55:39 -0700237ifeq ($(LOCAL_DATA_BINDING),true)
238data_binding_intermediates := $(intermediates.COMMON)/data-binding
239
240LOCAL_JAVACFLAGS += -processorpath $(DATA_BINDING_COMPILER) -s $(data_binding_intermediates)/anno-src
241LOCAL_JACK_FLAGS += --processorpath $(DATA_BINDING_COMPILER)
242
243LOCAL_STATIC_JAVA_LIBRARIES += databinding-baselibrary
244LOCAL_STATIC_JAVA_AAR_LIBRARIES += databinding-library databinding-adapters
245
246data_binding_res_in := $(LOCAL_RESOURCE_DIR)
247data_binding_res_out := $(data_binding_intermediates)/res
248
249# Replace with the processed merged res dir.
250LOCAL_RESOURCE_DIR := $(data_binding_res_out)
251
252LOCAL_AAPT_FLAGS += --auto-add-overlay --extra-packages com.android.databinding.library
253endif # LOCAL_DATA_BINDING
254
Ying Wange9dd9f22014-10-29 15:48:32 -0700255include $(BUILD_SYSTEM)/android_manifest.mk
256
Colin Cross8e404122014-02-06 14:45:37 -0800257#################################
258include $(BUILD_SYSTEM)/java.mk
259#################################
260
261LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
262ifeq ($(LOCAL_SDK_RES_VERSION),)
263 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
264endif
265
Colin Cross8e404122014-02-06 14:45:37 -0800266$(LOCAL_INTERMEDIATE_TARGETS): \
267 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
Michael Wright0fb087f2015-11-06 15:20:51 +0000268ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
Colin Cross8e404122014-02-06 14:45:37 -0800269$(LOCAL_INTERMEDIATE_TARGETS): \
270 PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION)
271else
272$(LOCAL_INTERMEDIATE_TARGETS): \
273 PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
274endif
275
Ying Wanged0361f2015-04-19 09:55:39 -0700276ifeq ($(LOCAL_DATA_BINDING),true)
277data_binding_stamp := $(data_binding_intermediates)/data-binding.stamp
278$(data_binding_stamp): PRIVATE_INTERMEDIATES := $(data_binding_intermediates)
279$(data_binding_stamp): PRIVATE_MANIFEST := $(full_android_manifest)
280# Generate code into $(LOCAL_INTERMEDIATE_SOURCE_DIR) so that the generated .java files
281# will be automatically picked up by function compile-java.
282$(data_binding_stamp): PRIVATE_SRC_OUT := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/data-binding
283$(data_binding_stamp): PRIVATE_XML_OUT := $(data_binding_intermediates)/xml
284$(data_binding_stamp): PRIVATE_RES_OUT := $(data_binding_res_out)
285$(data_binding_stamp): PRIVATE_RES_IN := $(data_binding_res_in)
286$(data_binding_stamp): PRIVATE_ANNO_SRC_DIR := $(data_binding_intermediates)/anno-src
287
288$(data_binding_stamp) : $(all_res_assets) $(full_android_manifest) \
289 $(DATA_BINDING_COMPILER)
290 @echo "Data-binding process: $@"
291 @rm -rf $(PRIVATE_INTERMEDIATES) $(PRIVATE_SRC_OUT) && \
292 mkdir -p $(PRIVATE_INTERMEDIATES) $(PRIVATE_SRC_OUT) \
293 $(PRIVATE_XML_OUT) $(PRIVATE_RES_OUT) $(PRIVATE_ANNO_SRC_DIR)
294 $(hide) java -classpath $(DATA_BINDING_COMPILER) android.databinding.tool.MakeCopy \
295 $(PRIVATE_MANIFEST) $(PRIVATE_SRC_OUT) $(PRIVATE_XML_OUT) $(PRIVATE_RES_OUT) $(PRIVATE_RES_IN)
296 $(hide) touch $@
297
298# Make sure the data-binding process happens before javac and generation of R.java.
299$(R_file_stamp) $(full_classes_compiled_jar) : $(data_binding_stamp)
300# The dependency path when jack is enabled
301$(built_dex_intermediate) : $(data_binding_stamp)
302endif # LOCAL_DATA_BINDING
303
Ying Wang61291922014-06-25 13:23:58 -0700304ifeq ($(need_compile_res),true)
Ying Wangdd71c852015-12-04 13:59:18 -0800305ifdef USE_AAPT2
306my_aapt_characteristics := $(TARGET_AAPT_CHARACTERISTICS)
307my_compiled_res_base_dir := $(intermediates)/flat-res
308include $(BUILD_SYSTEM)/aapt2.mk
309else # USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800310
311# Since we don't know where the real R.java file is going to end up,
312# we need to use another file to stand in its place. We'll just
313# copy the generated file to src/R.stamp, which means it will
314# have the same contents and timestamp as the actual file.
315#
316# At the same time, this will copy the R.java file to a central
317# 'R' directory to make it easier to add the files to an IDE.
318#
Colin Cross8e404122014-02-06 14:45:37 -0800319
320$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
321 $(intermediates.COMMON)/public_resources.xml
322$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
323$(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT) | $(ACP)
324 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
Martin Arenlindfb6985e2015-09-15 15:52:56 +0200325 @rm -rf $@ && mkdir -p $(dir $@)
Colin Cross8e404122014-02-06 14:45:37 -0800326 $(create-resource-java-files)
Ying Wangdd71c852015-12-04 13:59:18 -0800327 $(call find-generated-R.java)
Colin Cross8e404122014-02-06 14:45:37 -0800328
329$(proguard_options_file): $(R_file_stamp)
330
Ying Wangdbe23f52014-03-25 14:42:46 -0700331resource_export_package :=
Colin Cross8e404122014-02-06 14:45:37 -0800332ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
333# Put this module's resources into a PRODUCT-agnositc package that
334# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
335# files.
336resource_export_package := $(intermediates.COMMON)/package-export.apk
337$(R_file_stamp): $(resource_export_package)
338
339# add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
340# can't know anything about PRODUCT. Clear it out just for this target.
341$(resource_export_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
342$(resource_export_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
343$(resource_export_package): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT)
344 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
345 $(create-empty-package)
346 $(add-assets-to-package)
347endif
348
Ying Wangdd71c852015-12-04 13:59:18 -0800349endif # USE_AAPT2
350
Colin Cross8e404122014-02-06 14:45:37 -0800351# Other modules should depend on the BUILT module if
352# they want to use this module's R.java file.
353$(LOCAL_BUILT_MODULE): $(R_file_stamp)
354
Yohann Roussel37822c42015-01-09 10:36:40 +0100355ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200356ifneq ($(built_dex_intermediate),)
357$(built_dex_intermediate): $(R_file_stamp)
358endif
359ifneq ($(noshrob_classes_jack),)
360$(noshrob_classes_jack): $(R_file_stamp)
361endif
362ifneq ($(full_classes_jack),)
363$(full_classes_jack): $(R_file_stamp)
364endif
Yohann Roussel37822c42015-01-09 10:36:40 +0100365endif # LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200366
Colin Cross8e404122014-02-06 14:45:37 -0800367ifneq ($(full_classes_jar),)
368# If full_classes_jar is non-empty, we're building sources.
369# If we're building sources, the initial javac step (which
370# produces full_classes_compiled_jar) needs to ensure the
371# R.java and Manifest.java files have been generated first.
372$(full_classes_compiled_jar): $(R_file_stamp)
373endif
374
Ying Wang61291922014-06-25 13:23:58 -0700375endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800376
377ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
378# We need to explicitly clear this var so that we don't
379# inherit the value from whomever caused us to be built.
380$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
381else
382# Most packages should link against the resources defined by framework-res.
383# Even if they don't have their own resources, they may use framework
384# resources.
Michael Wright0fb087f2015-11-06 15:20:51 +0000385ifneq ($(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 -0800386# for released sdk versions, the platform resources were built into android.jar.
387framework_res_package_export := \
388 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
389framework_res_package_export_deps := $(framework_res_package_export)
390else # LOCAL_SDK_RES_VERSION
391framework_res_package_export := \
392 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
393# We can't depend directly on the export.apk file; it won't get its
394# PRIVATE_ vars set up correctly if we do. Instead, depend on the
395# corresponding R.stamp file, which lists the export.apk as a dependency.
396framework_res_package_export_deps := \
397 $(dir $(framework_res_package_export))src/R.stamp
398endif # LOCAL_SDK_RES_VERSION
Adam Lesinskide057c32014-03-13 18:48:27 -0700399all_library_res_package_exports := \
400 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700401 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700402 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk)
403
404all_library_res_package_export_deps := \
405 $(framework_res_package_export_deps) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700406 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700407 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp)
Ying Wangb5745642014-06-19 16:07:30 -0700408$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps)
Colin Cross8e404122014-02-06 14:45:37 -0800409$(LOCAL_INTERMEDIATE_TARGETS): \
Adam Lesinskide057c32014-03-13 18:48:27 -0700410 PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports)
Ying Wangdd71c852015-12-04 13:59:18 -0800411
412ifdef USE_AAPT2
413$(my_res_package) : $(all_library_res_package_export_deps)
414endif
Colin Cross8e404122014-02-06 14:45:37 -0800415endif # LOCAL_NO_STANDARD_LIBRARIES
416
417ifneq ($(full_classes_jar),)
418$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
Ying Wang33360dd2015-01-14 14:23:56 -0800419# Use the jarjar processed arhive as the initial package file.
420$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar)
Colin Cross8e404122014-02-06 14:45:37 -0800421$(LOCAL_BUILT_MODULE): $(built_dex)
Ying Wang33360dd2015-01-14 14:23:56 -0800422else
423$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE :=
424$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE :=
Colin Cross8e404122014-02-06 14:45:37 -0800425endif # full_classes_jar
426
Ying Wang96bcad42014-04-17 13:38:04 -0700427include $(BUILD_SYSTEM)/install_jni_libs.mk
Colin Cross8e404122014-02-06 14:45:37 -0800428
429# Pick a key to sign the package with. If this package hasn't specified
430# an explicit certificate, use the default.
431# Secure release builds will have their packages signed after the fact,
432# so it's ok for these private keys to be in the clear.
433ifeq ($(LOCAL_CERTIFICATE),)
434 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
435endif
436
437ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
438 # The special value "EXTERNAL" means that we will sign it with the
439 # default devkey, apply predexopt, but then expect the final .apk
440 # (after dexopting) to be signed by an outside tool.
441 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
442 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
443endif
444
445# If this is not an absolute certificate, assign it to a generic one.
446ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
447 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
448endif
449private_key := $(LOCAL_CERTIFICATE).pk8
450certificate := $(LOCAL_CERTIFICATE).x509.pem
451
452$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
453$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
454$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
455
456PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
457PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
458
459$(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(foreach c,\
460 $(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
461
462# Define the rule to build the actual package.
Ying Wang8e20ef62014-06-24 20:01:52 -0700463# PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>.
464$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
465# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
466$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
Colin Cross8e404122014-02-06 14:45:37 -0800467ifneq ($(TARGET_BUILD_APPS),)
468 # Include all resources for unbundled apps.
469 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
470endif
471ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
472 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG :=
473 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
474else
475 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG)
Ying Wang934008f2014-07-30 13:40:14 -0700476ifdef LOCAL_PACKAGE_SPLITS
477 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
478else
Colin Cross8e404122014-02-06 14:45:37 -0800479 $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG)
480endif
Ying Wang934008f2014-07-30 13:40:14 -0700481endif
Fredrik Roubertcc93f0c2015-01-28 21:29:38 +0100482$(LOCAL_BUILT_MODULE): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS)
Ying Wangdd71c852015-12-04 13:59:18 -0800483$(LOCAL_BUILT_MODULE) : $(jni_shared_libraries)
484ifdef USE_AAPT2
485$(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package)
486$(LOCAL_BUILT_MODULE) : $(my_res_package) $(AAPT2) | $(ACP)
487else
488$(LOCAL_BUILT_MODULE) : $(all_res_assets) $(full_android_manifest) $(AAPT)
489endif
Colin Cross8e404122014-02-06 14:45:37 -0800490 @echo "target Package: $(PRIVATE_MODULE) ($@)"
Ying Wangdd71c852015-12-04 13:59:18 -0800491ifdef USE_AAPT2
492ifdef LOCAL_JACK_ENABLED
493 $(call copy-file-to-new-target)
494else
495 @# TODO: implement merge-two-packages.
496 $(if $(PRIVATE_SOURCE_ARCHIVE),\
497 $(call merge-two-packages,$(PRIVATE_RES_PACKAGE) $(PRIVATE_SOURCE_ARCHIVE),$@),
498 $(call copy-file-to-new-target))
499endif
500else # USE_AAPT2
Yohann Roussel37822c42015-01-09 10:36:40 +0100501ifdef LOCAL_JACK_ENABLED
Colin Cross8e404122014-02-06 14:45:37 -0800502 $(create-empty-package)
Ying Wang33360dd2015-01-14 14:23:56 -0800503else
504 $(if $(PRIVATE_SOURCE_ARCHIVE),\
505 $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@),\
506 $(create-empty-package))
507endif
Colin Cross8e404122014-02-06 14:45:37 -0800508 $(add-assets-to-package)
Ying Wangdd71c852015-12-04 13:59:18 -0800509endif # USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800510ifneq ($(jni_shared_libraries),)
511 $(add-jni-shared-libs-to-package)
512endif
Ying Wang8b27d182015-03-27 11:07:17 -0700513ifeq ($(full_classes_jar),)
514# We don't build jar, need to add the Java resources here.
515 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
516else
Colin Cross8e404122014-02-06 14:45:37 -0800517 $(add-dex-to-package)
518endif
Yohann Roussel37822c42015-01-09 10:36:40 +0100519ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200520 $(add-carried-jack-resources)
521endif
Colin Cross8e404122014-02-06 14:45:37 -0800522ifdef LOCAL_DEX_PREOPT
Colin Cross8e404122014-02-06 14:45:37 -0800523ifneq (nostripping,$(LOCAL_DEX_PREOPT))
524 $(call dexpreopt-remove-classes.dex,$@)
525endif
526endif
Kenny Rootdff37552015-04-15 12:09:32 -0700527 $(sign-package)
Colin Cross8e404122014-02-06 14:45:37 -0800528
Ying Wang36142f62014-05-21 16:13:33 -0700529###############################
Ying Wang8070b202014-12-01 17:46:56 -0800530## Build dpi-specific apks, if it's apps_only build.
531ifdef TARGET_BUILD_APPS
532ifdef LOCAL_DPI_VARIANTS
533$(foreach d, $(LOCAL_DPI_VARIANTS), \
534 $(eval my_dpi := $(d)) \
535 $(eval include $(BUILD_SYSTEM)/dpi_specific_apk.mk))
536endif
537endif
538
539###############################
Ying Wang36142f62014-05-21 16:13:33 -0700540## Rule to build the odex file
541ifdef LOCAL_DEX_PREOPT
542$(built_odex): PRIVATE_DEX_FILE := $(built_dex)
Ying Wangdb48da72014-09-13 11:26:39 -0700543# Use pattern rule - we may have multiple built odex files.
544$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(built_dex)
Ying Wang994c2262014-05-28 13:34:59 -0700545 $(hide) mkdir -p $(dir $@) && rm -f $@
Ying Wang36142f62014-05-21 16:13:33 -0700546 $(add-dex-to-package)
547 $(hide) mv $@ $@.input
548 $(call dexpreopt-one-file,$@.input,$@)
549 $(hide) rm $@.input
550endif
551
Ying Wang1425e2d2014-07-22 15:42:11 -0700552###############################
553## APK splits
554ifdef LOCAL_PACKAGE_SPLITS
Ying Wang7f625aa2014-07-23 10:27:57 -0700555# LOCAL_PACKAGE_SPLITS is a list of resource labels.
Ying Wang114a0fc2014-10-01 12:01:04 -0700556# aapt will convert comma inside resource lable to underscore in the file names.
557my_split_suffixes := $(subst $(comma),_,$(LOCAL_PACKAGE_SPLITS))
558built_apk_splits := $(foreach s,$(my_split_suffixes),$(built_module_path)/package_$(s).apk)
559installed_apk_splits := $(foreach s,$(my_split_suffixes),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Ying Wang1425e2d2014-07-22 15:42:11 -0700560
Ying Wang7f625aa2014-07-23 10:27:57 -0700561# The splits should have been built in the same command building the base apk.
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800562# This rule just runs signing.
Ying Wang7f625aa2014-07-23 10:27:57 -0700563# Note that we explicily check the existence of the split apk and remove the
564# built base apk if the split apk isn't there.
565# That way the build system will rerun the aapt after the user changes the splitting parameters.
Ying Wang1425e2d2014-07-22 15:42:11 -0700566$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
567$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
Ying Wang7f625aa2014-07-23 10:27:57 -0700568$(built_apk_splits) : $(built_module_path)/%.apk : $(LOCAL_BUILT_MODULE)
569 $(hide) if [ ! -f $@ ]; then \
570 echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \
571 rm $<; exit 1; \
572 fi
573 $(sign-package)
Ying Wang1425e2d2014-07-22 15:42:11 -0700574
575# Rules to install the splits
Ying Wang7f625aa2014-07-23 10:27:57 -0700576$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(built_module_path)/package_%.apk | $(ACP)
577 @echo "Install: $@"
578 $(copy-file-to-new-target)
Ying Wang1425e2d2014-07-22 15:42:11 -0700579
580# Register the additional built and installed files.
581ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
582ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
Ying Wang114a0fc2014-10-01 12:01:04 -0700583 $(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 -0700584
585# Make sure to install the splits when you run "make <module_name>".
586$(my_register_name): $(installed_apk_splits)
Ying Wang16243612015-06-03 12:43:50 -0700587
588ifdef LOCAL_COMPATIBILITY_SUITE
589cts_testcase_file := $(foreach s,$(my_split_suffixes),$(COMPATIBILITY_TESTCASES_OUT_$(LOCAL_COMPATIBILITY_SUITE))/$(LOCAL_MODULE)_$(s).apk)
Ying Wang9d8a0622015-10-21 14:14:50 -0700590$(cts_testcase_file) : $(COMPATIBILITY_TESTCASES_OUT_$(LOCAL_COMPATIBILITY_SUITE))/$(LOCAL_MODULE)_%.apk : $(built_module_path)/package_%.apk | $(ACP)
Ying Wang16243612015-06-03 12:43:50 -0700591 $(copy-file-to-new-target)
592
593COMPATIBILITY.$(LOCAL_COMPATIBILITY_SUITE).FILES := \
594 $(COMPATIBILITY.$(LOCAL_COMPATIBILITY_SUITE).FILES) \
595 $(cts_testcase_file)
596
597$(my_register_name) : $(cts_testcase_file)
598endif # LOCAL_COMPATIBILITY_SUITE
Ying Wang1425e2d2014-07-22 15:42:11 -0700599endif # LOCAL_PACKAGE_SPLITS
600
Colin Cross8e404122014-02-06 14:45:37 -0800601# Save information about this package
602PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
603PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
604ifdef package_resource_overlays
605PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_OVERLAYS := $(package_resource_overlays)
606endif
607
608PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
609
Colin Cross8e404122014-02-06 14:45:37 -0800610endif # skip_definition
611
612# Reset internal variables.
613all_res_assets :=