blob: 2ffbcd4d96116dc976585cdc56a125ebd1ef63a1 [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
Adam Lesinskie758f932016-02-26 11:13:43 -0800118my_res_package :=
Ying Wange295c3d2016-02-24 14:11:55 -0800119ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800120# In aapt2 the last takes precedence.
121my_resource_dirs := $(call reverse-list,$(LOCAL_RESOURCE_DIR))
Adam Lesinskie758f932016-02-26 11:13:43 -0800122my_res_dir :=
123my_overlay_res_dirs :=
124
125ifneq ($(LOCAL_STATIC_ANDROID_LIBRARIES),)
126# If we are using static android libraries, every source file becomes an overlay.
127# This is to emulate old AAPT behavior which simulated library support.
128my_res_dir :=
129my_overlay_res_dirs := $(my_resource_dirs)
130else
131# Without static libraries, the first directory is our directory, which can then be
132# overlaid by the rest. (First directory in my_resource_dirs is last directory in
133# $(LOCAL_RESOURCE_DIR) due to it being reversed.
134my_res_dir := $(firstword $(my_resource_dirs))
135my_overlay_res_dirs := $(wordlist 2,999,$(my_resource_dirs))
136endif
137
Ying Wangdd71c852015-12-04 13:59:18 -0800138my_overlay_resources := $(strip \
Adam Lesinskie758f932016-02-26 11:13:43 -0800139 $(foreach d,$(my_overlay_res_dirs),\
Ying Wangdd71c852015-12-04 13:59:18 -0800140 $(addprefix $(d)/, \
141 $(call find-subdir-assets,$(d)))))
142
Ying Wangdd71c852015-12-04 13:59:18 -0800143my_res_resources := $(strip \
144 $(addprefix $(my_res_dir)/, \
145 $(call find-subdir-assets,$(my_res_dir))))
146
147all_resources := $(strip $(my_res_resources) $(my_overlay_resources))
148
149# The linked resource package.
150my_res_package := $(intermediates)/package-res.apk
151LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
152
153# Always run aapt2
154need_compile_res := true
155
Ying Wange295c3d2016-02-24 14:11:55 -0800156else # LOCAL_USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800157all_resources := $(strip \
158 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
159 $(addprefix $(dir)/, \
160 $(patsubst res/%,%, \
161 $(call find-subdir-assets,$(dir)) \
162 ) \
163 ) \
164 ))
165
Ying Wange295c3d2016-02-24 14:11:55 -0800166endif # LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800167
Ying Wang61291922014-06-25 13:23:58 -0700168ifneq ($(all_resources),)
169 need_compile_res := true
170endif
171
Colin Cross8e404122014-02-06 14:45:37 -0800172all_res_assets := $(strip $(all_assets) $(all_resources))
173
Ying Wang98ae7982014-12-18 14:53:52 -0800174
Colin Cross8e404122014-02-06 14:45:37 -0800175# If no assets or resources were found, clear the directory variables so
176# we don't try to build them.
Ying Wang4cb04992014-07-29 10:34:30 -0700177ifneq (true,$(need_compile_asset))
Colin Cross8e404122014-02-06 14:45:37 -0800178LOCAL_ASSET_DIR:=
179endif
Ying Wang61291922014-06-25 13:23:58 -0700180ifneq (true,$(need_compile_res))
Colin Cross8e404122014-02-06 14:45:37 -0800181LOCAL_RESOURCE_DIR:=
182R_file_stamp :=
183else
184# Make sure that R_file_stamp inherits the proper PRIVATE vars.
185# If R.stamp moves, be sure to update the framework makefile,
186# which has intimate knowledge of its location.
Ying Wang98ae7982014-12-18 14:53:52 -0800187R_file_stamp := $(intermediates.COMMON)/src/R.stamp
Colin Cross8e404122014-02-06 14:45:37 -0800188LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
189endif
190
191LOCAL_BUILT_MODULE_STEM := package.apk
Ying Wangaf9757e2014-07-17 21:24:42 -0700192LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
Colin Cross8e404122014-02-06 14:45:37 -0800193
194LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
195ifndef LOCAL_PROGUARD_ENABLED
196ifneq ($(DISABLE_PROGUARD),true)
197 LOCAL_PROGUARD_ENABLED :=full
198endif
199endif
200ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
201 # the package explicitly request to disable proguard.
202 LOCAL_PROGUARD_ENABLED :=
203endif
204proguard_options_file :=
205ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
Ying Wang61291922014-06-25 13:23:58 -0700206ifeq ($(need_compile_res),true)
Ying Wang98ae7982014-12-18 14:53:52 -0800207 proguard_options_file := $(intermediates.COMMON)/proguard_options
Ying Wang61291922014-06-25 13:23:58 -0700208endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800209endif # !custom
210LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
211
Yohann Roussel37822c42015-01-09 10:36:40 +0100212ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200213ifndef LOCAL_JACK_PROGUARD_FLAGS
214 LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS)
215endif
216LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS)
Yohann Roussel37822c42015-01-09 10:36:40 +0100217endif # LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200218
Colin Cross8e404122014-02-06 14:45:37 -0800219ifeq (true,$(EMMA_INSTRUMENT))
220ifndef LOCAL_EMMA_INSTRUMENT
221# No emma for test apks.
Ying Wang324ffb22015-11-06 11:22:28 -0800222ifeq (,$(LOCAL_INSTRUMENTATION_FOR))
Colin Cross8e404122014-02-06 14:45:37 -0800223LOCAL_EMMA_INSTRUMENT := true
224endif # No test apk
225endif # LOCAL_EMMA_INSTRUMENT is not set
226else
227LOCAL_EMMA_INSTRUMENT := false
228endif # EMMA_INSTRUMENT is true
229
230ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
231ifeq (true,$(EMMA_INSTRUMENT_STATIC))
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100232ifdef LOCAL_JACK_ENABLED
233# Jack supports coverage with Jacoco
234LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
235else
Colin Cross8e404122014-02-06 14:45:37 -0800236LOCAL_STATIC_JAVA_LIBRARIES += emma
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100237endif # LOCAL_JACK_ENABLED
Colin Cross8e404122014-02-06 14:45:37 -0800238else
239ifdef LOCAL_SDK_VERSION
240ifdef TARGET_BUILD_APPS
241# In unbundled build merge the emma library into the apk.
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100242ifdef LOCAL_JACK_ENABLED
243# Jack supports coverage with Jacoco
244LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
245else
Colin Cross8e404122014-02-06 14:45:37 -0800246LOCAL_STATIC_JAVA_LIBRARIES += emma
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100247endif # LOCAL_JACK_ENABLED
Colin Cross8e404122014-02-06 14:45:37 -0800248else
249# If build against the SDK in full build, core.jar is not used,
250# we have to use prebiult emma.jar to make Proguard happy;
251# Otherwise emma classes are included in core.jar.
252LOCAL_PROGUARD_FLAGS += -libraryjars $(EMMA_JAR)
253endif # full build
254endif # LOCAL_SDK_VERSION
255endif # EMMA_INSTRUMENT_STATIC
256endif # LOCAL_EMMA_INSTRUMENT
257
258rs_compatibility_jni_libs :=
259
Ying Wanged0361f2015-04-19 09:55:39 -0700260ifeq ($(LOCAL_DATA_BINDING),true)
261data_binding_intermediates := $(intermediates.COMMON)/data-binding
262
263LOCAL_JAVACFLAGS += -processorpath $(DATA_BINDING_COMPILER) -s $(data_binding_intermediates)/anno-src
264LOCAL_JACK_FLAGS += --processorpath $(DATA_BINDING_COMPILER)
265
266LOCAL_STATIC_JAVA_LIBRARIES += databinding-baselibrary
267LOCAL_STATIC_JAVA_AAR_LIBRARIES += databinding-library databinding-adapters
268
269data_binding_res_in := $(LOCAL_RESOURCE_DIR)
270data_binding_res_out := $(data_binding_intermediates)/res
271
272# Replace with the processed merged res dir.
273LOCAL_RESOURCE_DIR := $(data_binding_res_out)
274
275LOCAL_AAPT_FLAGS += --auto-add-overlay --extra-packages com.android.databinding.library
276endif # LOCAL_DATA_BINDING
277
Ying Wange9dd9f22014-10-29 15:48:32 -0700278include $(BUILD_SYSTEM)/android_manifest.mk
279
Colin Cross8e404122014-02-06 14:45:37 -0800280#################################
281include $(BUILD_SYSTEM)/java.mk
282#################################
283
284LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
285ifeq ($(LOCAL_SDK_RES_VERSION),)
286 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
287endif
288
Colin Cross8e404122014-02-06 14:45:37 -0800289$(LOCAL_INTERMEDIATE_TARGETS): \
290 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
Michael Wright0fb087f2015-11-06 15:20:51 +0000291ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
Colin Cross8e404122014-02-06 14:45:37 -0800292$(LOCAL_INTERMEDIATE_TARGETS): \
293 PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION)
294else
295$(LOCAL_INTERMEDIATE_TARGETS): \
296 PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
297endif
298
Ying Wanged0361f2015-04-19 09:55:39 -0700299ifeq ($(LOCAL_DATA_BINDING),true)
300data_binding_stamp := $(data_binding_intermediates)/data-binding.stamp
301$(data_binding_stamp): PRIVATE_INTERMEDIATES := $(data_binding_intermediates)
302$(data_binding_stamp): PRIVATE_MANIFEST := $(full_android_manifest)
303# Generate code into $(LOCAL_INTERMEDIATE_SOURCE_DIR) so that the generated .java files
304# will be automatically picked up by function compile-java.
305$(data_binding_stamp): PRIVATE_SRC_OUT := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/data-binding
306$(data_binding_stamp): PRIVATE_XML_OUT := $(data_binding_intermediates)/xml
307$(data_binding_stamp): PRIVATE_RES_OUT := $(data_binding_res_out)
308$(data_binding_stamp): PRIVATE_RES_IN := $(data_binding_res_in)
309$(data_binding_stamp): PRIVATE_ANNO_SRC_DIR := $(data_binding_intermediates)/anno-src
310
311$(data_binding_stamp) : $(all_res_assets) $(full_android_manifest) \
312 $(DATA_BINDING_COMPILER)
313 @echo "Data-binding process: $@"
314 @rm -rf $(PRIVATE_INTERMEDIATES) $(PRIVATE_SRC_OUT) && \
315 mkdir -p $(PRIVATE_INTERMEDIATES) $(PRIVATE_SRC_OUT) \
316 $(PRIVATE_XML_OUT) $(PRIVATE_RES_OUT) $(PRIVATE_ANNO_SRC_DIR)
317 $(hide) java -classpath $(DATA_BINDING_COMPILER) android.databinding.tool.MakeCopy \
318 $(PRIVATE_MANIFEST) $(PRIVATE_SRC_OUT) $(PRIVATE_XML_OUT) $(PRIVATE_RES_OUT) $(PRIVATE_RES_IN)
319 $(hide) touch $@
320
321# Make sure the data-binding process happens before javac and generation of R.java.
322$(R_file_stamp) $(full_classes_compiled_jar) : $(data_binding_stamp)
323# The dependency path when jack is enabled
324$(built_dex_intermediate) : $(data_binding_stamp)
325endif # LOCAL_DATA_BINDING
326
Ying Wang61291922014-06-25 13:23:58 -0700327ifeq ($(need_compile_res),true)
Ying Wange295c3d2016-02-24 14:11:55 -0800328ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800329my_compiled_res_base_dir := $(intermediates)/flat-res
Ying Wange295c3d2016-02-24 14:11:55 -0800330my_generated_res_dirs := $(rs_generated_res_dir)
331my_generated_res_dirs_deps := $(RenderScript_file_stamp)
Adam Lesinskie758f932016-02-26 11:13:43 -0800332# Add AAPT2 link specific flags.
333$(my_res_package): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --no-static-lib-packages
334$(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS := $(TARGET_AAPT_CHARACTERISTICS)
Ying Wangdd71c852015-12-04 13:59:18 -0800335include $(BUILD_SYSTEM)/aapt2.mk
Ying Wange295c3d2016-02-24 14:11:55 -0800336else # LOCAL_USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800337
338# Since we don't know where the real R.java file is going to end up,
339# we need to use another file to stand in its place. We'll just
340# copy the generated file to src/R.stamp, which means it will
341# have the same contents and timestamp as the actual file.
342#
343# At the same time, this will copy the R.java file to a central
344# 'R' directory to make it easier to add the files to an IDE.
345#
Colin Cross8e404122014-02-06 14:45:37 -0800346
347$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
348 $(intermediates.COMMON)/public_resources.xml
349$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
350$(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT) | $(ACP)
351 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
Martin Arenlindfb6985e2015-09-15 15:52:56 +0200352 @rm -rf $@ && mkdir -p $(dir $@)
Colin Cross8e404122014-02-06 14:45:37 -0800353 $(create-resource-java-files)
Ying Wangdd71c852015-12-04 13:59:18 -0800354 $(call find-generated-R.java)
Colin Cross8e404122014-02-06 14:45:37 -0800355
356$(proguard_options_file): $(R_file_stamp)
357
Ying Wangdbe23f52014-03-25 14:42:46 -0700358resource_export_package :=
Colin Cross8e404122014-02-06 14:45:37 -0800359ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
360# Put this module's resources into a PRODUCT-agnositc package that
361# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
362# files.
363resource_export_package := $(intermediates.COMMON)/package-export.apk
364$(R_file_stamp): $(resource_export_package)
365
366# add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
367# can't know anything about PRODUCT. Clear it out just for this target.
368$(resource_export_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
369$(resource_export_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
370$(resource_export_package): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT)
371 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
372 $(create-empty-package)
373 $(add-assets-to-package)
374endif
375
Ying Wange295c3d2016-02-24 14:11:55 -0800376endif # LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800377
Colin Cross8e404122014-02-06 14:45:37 -0800378# Other modules should depend on the BUILT module if
379# they want to use this module's R.java file.
380$(LOCAL_BUILT_MODULE): $(R_file_stamp)
381
Yohann Roussel37822c42015-01-09 10:36:40 +0100382ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200383ifneq ($(built_dex_intermediate),)
384$(built_dex_intermediate): $(R_file_stamp)
385endif
386ifneq ($(noshrob_classes_jack),)
387$(noshrob_classes_jack): $(R_file_stamp)
388endif
389ifneq ($(full_classes_jack),)
390$(full_classes_jack): $(R_file_stamp)
391endif
Yohann Roussel37822c42015-01-09 10:36:40 +0100392endif # LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200393
Colin Cross8e404122014-02-06 14:45:37 -0800394ifneq ($(full_classes_jar),)
395# If full_classes_jar is non-empty, we're building sources.
396# If we're building sources, the initial javac step (which
397# produces full_classes_compiled_jar) needs to ensure the
398# R.java and Manifest.java files have been generated first.
399$(full_classes_compiled_jar): $(R_file_stamp)
400endif
401
Ying Wang61291922014-06-25 13:23:58 -0700402endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800403
404ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
405# We need to explicitly clear this var so that we don't
406# inherit the value from whomever caused us to be built.
407$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
408else
409# Most packages should link against the resources defined by framework-res.
410# Even if they don't have their own resources, they may use framework
411# resources.
Michael Wright0fb087f2015-11-06 15:20:51 +0000412ifneq ($(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 -0800413# for released sdk versions, the platform resources were built into android.jar.
414framework_res_package_export := \
415 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
416framework_res_package_export_deps := $(framework_res_package_export)
417else # LOCAL_SDK_RES_VERSION
418framework_res_package_export := \
419 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
420# We can't depend directly on the export.apk file; it won't get its
421# PRIVATE_ vars set up correctly if we do. Instead, depend on the
422# corresponding R.stamp file, which lists the export.apk as a dependency.
423framework_res_package_export_deps := \
424 $(dir $(framework_res_package_export))src/R.stamp
425endif # LOCAL_SDK_RES_VERSION
Adam Lesinskide057c32014-03-13 18:48:27 -0700426all_library_res_package_exports := \
427 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700428 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700429 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk)
430
431all_library_res_package_export_deps := \
432 $(framework_res_package_export_deps) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700433 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700434 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp)
Ying Wangb5745642014-06-19 16:07:30 -0700435$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps)
Colin Cross8e404122014-02-06 14:45:37 -0800436$(LOCAL_INTERMEDIATE_TARGETS): \
Adam Lesinskide057c32014-03-13 18:48:27 -0700437 PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports)
Ying Wangdd71c852015-12-04 13:59:18 -0800438
Ying Wange295c3d2016-02-24 14:11:55 -0800439ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800440$(my_res_package) : $(all_library_res_package_export_deps)
441endif
Colin Cross8e404122014-02-06 14:45:37 -0800442endif # LOCAL_NO_STANDARD_LIBRARIES
443
444ifneq ($(full_classes_jar),)
445$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
Ying Wang33360dd2015-01-14 14:23:56 -0800446# Use the jarjar processed arhive as the initial package file.
447$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar)
Colin Cross8e404122014-02-06 14:45:37 -0800448$(LOCAL_BUILT_MODULE): $(built_dex)
Ying Wang33360dd2015-01-14 14:23:56 -0800449else
450$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE :=
451$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE :=
Colin Cross8e404122014-02-06 14:45:37 -0800452endif # full_classes_jar
453
Ying Wang96bcad42014-04-17 13:38:04 -0700454include $(BUILD_SYSTEM)/install_jni_libs.mk
Colin Cross8e404122014-02-06 14:45:37 -0800455
456# Pick a key to sign the package with. If this package hasn't specified
457# an explicit certificate, use the default.
458# Secure release builds will have their packages signed after the fact,
459# so it's ok for these private keys to be in the clear.
460ifeq ($(LOCAL_CERTIFICATE),)
461 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
462endif
463
464ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
465 # The special value "EXTERNAL" means that we will sign it with the
466 # default devkey, apply predexopt, but then expect the final .apk
467 # (after dexopting) to be signed by an outside tool.
468 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
469 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
470endif
471
472# If this is not an absolute certificate, assign it to a generic one.
473ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
474 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
475endif
476private_key := $(LOCAL_CERTIFICATE).pk8
477certificate := $(LOCAL_CERTIFICATE).x509.pem
478
479$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
480$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
481$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
482
483PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
484PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
485
486$(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(foreach c,\
487 $(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
488
489# Define the rule to build the actual package.
Ying Wang8e20ef62014-06-24 20:01:52 -0700490# PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>.
491$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
492# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
493$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
Colin Cross8e404122014-02-06 14:45:37 -0800494ifneq ($(TARGET_BUILD_APPS),)
495 # Include all resources for unbundled apps.
496 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
497endif
498ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
Adam Lesinskie758f932016-02-26 11:13:43 -0800499 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG :=
500 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
Colin Cross8e404122014-02-06 14:45:37 -0800501else
Adam Lesinskie758f932016-02-26 11:13:43 -0800502 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG)
Ying Wang934008f2014-07-30 13:40:14 -0700503ifdef LOCAL_PACKAGE_SPLITS
Adam Lesinskie758f932016-02-26 11:13:43 -0800504 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
Ying Wang934008f2014-07-30 13:40:14 -0700505else
Adam Lesinskie758f932016-02-26 11:13:43 -0800506 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG)
Colin Cross8e404122014-02-06 14:45:37 -0800507endif
Ying Wang934008f2014-07-30 13:40:14 -0700508endif
Fredrik Roubertcc93f0c2015-01-28 21:29:38 +0100509$(LOCAL_BUILT_MODULE): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS)
Ying Wangdd71c852015-12-04 13:59:18 -0800510$(LOCAL_BUILT_MODULE) : $(jni_shared_libraries)
Ying Wange295c3d2016-02-24 14:11:55 -0800511ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800512$(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package)
513$(LOCAL_BUILT_MODULE) : $(my_res_package) $(AAPT2) | $(ACP)
514else
515$(LOCAL_BUILT_MODULE) : $(all_res_assets) $(full_android_manifest) $(AAPT)
516endif
Colin Cross8e404122014-02-06 14:45:37 -0800517 @echo "target Package: $(PRIVATE_MODULE) ($@)"
Ying Wange295c3d2016-02-24 14:11:55 -0800518ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800519ifdef LOCAL_JACK_ENABLED
520 $(call copy-file-to-new-target)
521else
522 @# TODO: implement merge-two-packages.
523 $(if $(PRIVATE_SOURCE_ARCHIVE),\
524 $(call merge-two-packages,$(PRIVATE_RES_PACKAGE) $(PRIVATE_SOURCE_ARCHIVE),$@),
525 $(call copy-file-to-new-target))
526endif
Ying Wange295c3d2016-02-24 14:11:55 -0800527else # LOCAL_USE_AAPT2
Yohann Roussel37822c42015-01-09 10:36:40 +0100528ifdef LOCAL_JACK_ENABLED
Colin Cross8e404122014-02-06 14:45:37 -0800529 $(create-empty-package)
Ying Wang33360dd2015-01-14 14:23:56 -0800530else
531 $(if $(PRIVATE_SOURCE_ARCHIVE),\
532 $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@),\
533 $(create-empty-package))
534endif
Colin Cross8e404122014-02-06 14:45:37 -0800535 $(add-assets-to-package)
Ying Wange295c3d2016-02-24 14:11:55 -0800536endif # LOCAL_USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800537ifneq ($(jni_shared_libraries),)
538 $(add-jni-shared-libs-to-package)
539endif
Ying Wang8b27d182015-03-27 11:07:17 -0700540ifeq ($(full_classes_jar),)
541# We don't build jar, need to add the Java resources here.
542 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
543else
Colin Cross8e404122014-02-06 14:45:37 -0800544 $(add-dex-to-package)
545endif
Yohann Roussel37822c42015-01-09 10:36:40 +0100546ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200547 $(add-carried-jack-resources)
548endif
Colin Cross8e404122014-02-06 14:45:37 -0800549ifdef LOCAL_DEX_PREOPT
Colin Cross8e404122014-02-06 14:45:37 -0800550ifneq (nostripping,$(LOCAL_DEX_PREOPT))
551 $(call dexpreopt-remove-classes.dex,$@)
552endif
553endif
Kenny Rootdff37552015-04-15 12:09:32 -0700554 $(sign-package)
Colin Cross8e404122014-02-06 14:45:37 -0800555
Ying Wang36142f62014-05-21 16:13:33 -0700556###############################
Ying Wang8070b202014-12-01 17:46:56 -0800557## Build dpi-specific apks, if it's apps_only build.
558ifdef TARGET_BUILD_APPS
559ifdef LOCAL_DPI_VARIANTS
560$(foreach d, $(LOCAL_DPI_VARIANTS), \
561 $(eval my_dpi := $(d)) \
562 $(eval include $(BUILD_SYSTEM)/dpi_specific_apk.mk))
563endif
564endif
565
566###############################
Ying Wang36142f62014-05-21 16:13:33 -0700567## Rule to build the odex file
568ifdef LOCAL_DEX_PREOPT
569$(built_odex): PRIVATE_DEX_FILE := $(built_dex)
Ying Wangdb48da72014-09-13 11:26:39 -0700570# Use pattern rule - we may have multiple built odex files.
571$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(built_dex)
Ying Wang994c2262014-05-28 13:34:59 -0700572 $(hide) mkdir -p $(dir $@) && rm -f $@
Ying Wang36142f62014-05-21 16:13:33 -0700573 $(add-dex-to-package)
574 $(hide) mv $@ $@.input
575 $(call dexpreopt-one-file,$@.input,$@)
576 $(hide) rm $@.input
577endif
578
Ying Wang1425e2d2014-07-22 15:42:11 -0700579###############################
580## APK splits
581ifdef LOCAL_PACKAGE_SPLITS
Ying Wang7f625aa2014-07-23 10:27:57 -0700582# LOCAL_PACKAGE_SPLITS is a list of resource labels.
Ying Wang114a0fc2014-10-01 12:01:04 -0700583# aapt will convert comma inside resource lable to underscore in the file names.
584my_split_suffixes := $(subst $(comma),_,$(LOCAL_PACKAGE_SPLITS))
585built_apk_splits := $(foreach s,$(my_split_suffixes),$(built_module_path)/package_$(s).apk)
586installed_apk_splits := $(foreach s,$(my_split_suffixes),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Ying Wang1425e2d2014-07-22 15:42:11 -0700587
Ying Wang7f625aa2014-07-23 10:27:57 -0700588# The splits should have been built in the same command building the base apk.
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800589# This rule just runs signing.
Ying Wang7f625aa2014-07-23 10:27:57 -0700590# Note that we explicily check the existence of the split apk and remove the
591# built base apk if the split apk isn't there.
592# That way the build system will rerun the aapt after the user changes the splitting parameters.
Ying Wang1425e2d2014-07-22 15:42:11 -0700593$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
594$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
Ying Wang7f625aa2014-07-23 10:27:57 -0700595$(built_apk_splits) : $(built_module_path)/%.apk : $(LOCAL_BUILT_MODULE)
596 $(hide) if [ ! -f $@ ]; then \
597 echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \
598 rm $<; exit 1; \
599 fi
600 $(sign-package)
Ying Wang1425e2d2014-07-22 15:42:11 -0700601
602# Rules to install the splits
Ying Wang7f625aa2014-07-23 10:27:57 -0700603$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(built_module_path)/package_%.apk | $(ACP)
604 @echo "Install: $@"
605 $(copy-file-to-new-target)
Ying Wang1425e2d2014-07-22 15:42:11 -0700606
607# Register the additional built and installed files.
608ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
609ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
Ying Wang114a0fc2014-10-01 12:01:04 -0700610 $(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 -0700611
612# Make sure to install the splits when you run "make <module_name>".
613$(my_register_name): $(installed_apk_splits)
Ying Wang16243612015-06-03 12:43:50 -0700614
615ifdef LOCAL_COMPATIBILITY_SUITE
616cts_testcase_file := $(foreach s,$(my_split_suffixes),$(COMPATIBILITY_TESTCASES_OUT_$(LOCAL_COMPATIBILITY_SUITE))/$(LOCAL_MODULE)_$(s).apk)
Ying Wang9d8a0622015-10-21 14:14:50 -0700617$(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 -0700618 $(copy-file-to-new-target)
619
620COMPATIBILITY.$(LOCAL_COMPATIBILITY_SUITE).FILES := \
621 $(COMPATIBILITY.$(LOCAL_COMPATIBILITY_SUITE).FILES) \
622 $(cts_testcase_file)
623
624$(my_register_name) : $(cts_testcase_file)
625endif # LOCAL_COMPATIBILITY_SUITE
Ying Wang1425e2d2014-07-22 15:42:11 -0700626endif # LOCAL_PACKAGE_SPLITS
627
Colin Cross8e404122014-02-06 14:45:37 -0800628# Save information about this package
629PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
630PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
631ifdef package_resource_overlays
632PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_OVERLAYS := $(package_resource_overlays)
633endif
634
635PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
636
Colin Cross8e404122014-02-06 14:45:37 -0800637endif # skip_definition
638
639# Reset internal variables.
640all_res_assets :=