blob: 57d6f4b9ac6e910111c334a194d157f1e6f48563 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -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
Joe Onorato899e62a2010-02-04 17:37:21 -080028
29# If this makefile is being read from within an inheritance,
30# use the new values.
31skip_definition:=
32ifdef LOCAL_PACKAGE_OVERRIDES
33 package_overridden := $(call set-inherited-package-variables)
34 ifeq ($(strip $(package_overridden)),)
35 skip_definition := true
36 endif
37endif
38
39ifndef skip_definition
40
The Android Open Source Project88b60792009-03-03 19:28:42 -080041LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME))
42ifeq ($(LOCAL_PACKAGE_NAME),)
43$(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
44endif
45
The Android Open Source Project88b60792009-03-03 19:28:42 -080046ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
47$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX)
48endif
49LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
50
51ifneq ($(strip $(LOCAL_MODULE)),)
52$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE)
53endif
54LOCAL_MODULE := $(LOCAL_PACKAGE_NAME)
55
56# Android packages should use Android resources or assets.
57ifneq (,$(LOCAL_JAVA_RESOURCE_DIRS))
58$(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_DIRS)
59endif
60ifneq (,$(LOCAL_JAVA_RESOURCE_FILES))
61$(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_FILES)
62endif
63
Evan Charlton121a7872010-07-23 11:03:29 -070064ifeq ($(strip $(LOCAL_MANIFEST_FILE)),)
65LOCAL_MANIFEST_FILE := AndroidManifest.xml
66endif
67
The Android Open Source Project88b60792009-03-03 19:28:42 -080068ifneq ($(strip $(LOCAL_MODULE_CLASS)),)
69$(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS)
70endif
71LOCAL_MODULE_CLASS := APPS
72
The Android Open Source Project2f312932009-03-09 11:52:11 -070073# Package LOCAL_MODULE_TAGS default to optional
74LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
75ifeq ($(LOCAL_MODULE_TAGS),)
76LOCAL_MODULE_TAGS := optional
77endif
78
Ying Wangc61d5932010-03-10 16:02:42 -080079ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),)
80# Force localization check if it's not tagged as tests.
81LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z
82endif
83
The Android Open Source Project88b60792009-03-03 19:28:42 -080084ifeq (,$(LOCAL_ASSET_DIR))
85LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
86endif
87
88ifeq (,$(LOCAL_RESOURCE_DIR))
89 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
90endif
91LOCAL_RESOURCE_DIR := \
Bjorn Bringerta7ab17d2010-01-14 17:33:44 +000092 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
93 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
94 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
95 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -080096 $(LOCAL_RESOURCE_DIR)
97
The Android Open Source Project88b60792009-03-03 19:28:42 -080098all_assets := $(call find-subdir-assets,$(LOCAL_ASSET_DIR))
99all_assets := $(addprefix $(LOCAL_ASSET_DIR)/,$(patsubst assets/%,%,$(all_assets)))
100
101all_resources := $(strip \
102 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
103 $(addprefix $(dir)/, \
104 $(patsubst res/%,%, \
105 $(call find-subdir-assets,$(dir)) \
106 ) \
107 ) \
108 ))
109
110all_res_assets := $(strip $(all_assets) $(all_resources))
111
Ying Wang6ef046c2009-12-07 18:14:00 -0800112package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800113# If no assets or resources were found, clear the directory variables so
114# we don't try to build them.
115ifeq (,$(all_assets))
116LOCAL_ASSET_DIR:=
117endif
118ifeq (,$(all_resources))
119LOCAL_RESOURCE_DIR:=
120R_file_stamp :=
121else
122# Make sure that R_file_stamp inherits the proper PRIVATE vars.
123# If R.stamp moves, be sure to update the framework makefile,
124# which has intimate knowledge of its location.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800125R_file_stamp := $(package_expected_intermediates_COMMON)/src/R.stamp
126LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
127endif
128
129LOCAL_BUILT_MODULE_STEM := package.apk
130
Ying Wang3b2bdf12010-02-01 09:51:23 -0800131LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
Ying Wang85ab4972010-02-19 18:39:13 -0800132ifndef LOCAL_PROGUARD_ENABLED
133ifneq ($(filter user userdebug, $(TARGET_BUILD_VARIANT)),)
134 # turn on Proguard by default for user & userdebug build
135 LOCAL_PROGUARD_ENABLED :=full
136endif
137endif
138ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
139 # the package explicitly request to disable proguard.
140 LOCAL_PROGUARD_ENABLED :=
141endif
Ying Wang3b2bdf12010-02-01 09:51:23 -0800142proguard_options_file :=
143ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
144ifneq ($(all_resources),)
Ying Wanga17463f2010-03-03 14:32:06 -0800145 proguard_options_file := $(package_expected_intermediates_COMMON)/proguard_options
Ying Wang3b2bdf12010-02-01 09:51:23 -0800146endif # all_resources
147endif # !custom
Ying Wanga17463f2010-03-03 14:32:06 -0800148LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
Joe Onorato2daa2b32009-08-30 13:39:24 -0700149
Ying Wange7874c42010-09-17 16:36:06 -0700150ifeq (true,$(WITH_DEXPREOPT))
Ying Wang94978cf2011-01-12 11:12:06 -0800151ifeq (,$(TARGET_BUILD_APPS))
Ying Wange7874c42010-09-17 16:36:06 -0700152ifneq (,$(LOCAL_SRC_FILES))
153ifndef LOCAL_DEX_PREOPT
154LOCAL_DEX_PREOPT := true
155endif
156endif
157endif
Ying Wang94978cf2011-01-12 11:12:06 -0800158endif
Ying Wange7874c42010-09-17 16:36:06 -0700159
The Android Open Source Project88b60792009-03-03 19:28:42 -0800160# The dex files go in the package, so we don't
161# want to install them separately for this module.
162old_DONT_INSTALL_DEX_FILES := $(DONT_INSTALL_DEX_FILES)
163DONT_INSTALL_DEX_FILES := true
164#################################
165include $(BUILD_SYSTEM)/java.mk
166#################################
167DONT_INSTALL_DEX_FILES := $(old_DONT_INSTALL_DEX_FILES)
168old_DONT_INSTALL_DEX_FILES =
169
Evan Charlton121a7872010-07-23 11:03:29 -0700170full_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800171$(LOCAL_INTERMEDIATE_TARGETS): \
172 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
173
174ifneq ($(all_resources),)
175
176# Since we don't know where the real R.java file is going to end up,
177# we need to use another file to stand in its place. We'll just
178# copy the generated file to src/R.stamp, which means it will
179# have the same contents and timestamp as the actual file.
180#
181# At the same time, this will copy the R.java file to a central
182# 'R' directory to make it easier to add the files to an IDE.
183#
184#TODO: use PRIVATE_SOURCE_INTERMEDIATES_DIR instead of
185# $(intermediates.COMMON)/src
186ifneq ($(package_expected_intermediates_COMMON),$(intermediates.COMMON))
187 $(error $(LOCAL_MODULE): internal error: expected intermediates.COMMON "$(package_expected_intermediates_COMMON)" != intermediates.COMMON "$(intermediates.COMMON)")
188endif
189
190$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
191 $(intermediates.COMMON)/public_resources.xml
Joe Onorato2daa2b32009-08-30 13:39:24 -0700192$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
Ying Wang0bd59a02010-07-15 17:17:52 -0700193$(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT) | $(ACP)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800194 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
195 @rm -f $@
196 $(create-resource-java-files)
197 $(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
198 -name Manifest.java 2> /dev/null`; do \
Patrick Scottfa30f5b2010-11-05 15:00:50 -0400199 dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_MANIFEST_FILE`; \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800200 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
201 $(ACP) -fpt $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
202 done;
203 $(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
204 -name R.java 2> /dev/null`; do \
Patrick Scottfa30f5b2010-11-05 15:00:50 -0400205 dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_R_FILE`; \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800206 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
207 $(ACP) -fpt $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
208 || exit 31; \
209 $(ACP) -fpt $$GENERATED_R_FILE $@ || exit 32; \
210 done; \
211
Joe Onorato2daa2b32009-08-30 13:39:24 -0700212$(proguard_options_file): $(R_file_stamp)
213
The Android Open Source Project88b60792009-03-03 19:28:42 -0800214ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
215# Put this module's resources into a PRODUCT-agnositc package that
216# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
217# files.
218resource_export_package := $(intermediates.COMMON)/package-export.apk
219$(R_file_stamp): $(resource_export_package)
220
221# add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
222# can't know anything about PRODUCT. Clear it out just for this target.
223$(resource_export_package): PRODUCT_AAPT_CONFIG :=
Ying Wang035ef062010-08-18 20:30:52 -0700224$(resource_export_package): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800225 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
226 $(create-empty-package)
227 $(add-assets-to-package)
228endif
229
230# Other modules should depend on the BUILT module if
231# they want to use this module's R.java file.
232$(LOCAL_BUILT_MODULE): $(R_file_stamp)
233
234ifneq ($(full_classes_jar),)
235# If full_classes_jar is non-empty, we're building sources.
236# If we're building sources, the initial javac step (which
237# produces full_classes_compiled_jar) needs to ensure the
238# R.java and Manifest.java files have been generated first.
239$(full_classes_compiled_jar): $(R_file_stamp)
240endif
241
242endif # all_resources
243
244ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
245# We need to explicitly clear this var so that we don't
246# inherit the value from whomever caused us to be built.
247$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
248else
249# Most packages should link against the resources defined by framework-res.
250# Even if they don't have their own resources, they may use framework
251# resources.
Ying Wang0f6f4ca2010-06-09 10:26:26 -0700252ifneq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
253# for released sdk versions, the platform resources were built into android.jar.
254framework_res_package_export := \
255 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/android.jar
256framework_res_package_export_deps := $(framework_res_package_export)
257else # LOCAL_SDK_VERSION
The Android Open Source Project88b60792009-03-03 19:28:42 -0800258framework_res_package_export := \
259 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
The Android Open Source Project88b60792009-03-03 19:28:42 -0800260# We can't depend directly on the export.apk file; it won't get its
261# PRIVATE_ vars set up correctly if we do. Instead, depend on the
262# corresponding R.stamp file, which lists the export.apk as a dependency.
263framework_res_package_export_deps := \
264 $(dir $(framework_res_package_export))src/R.stamp
Ying Wang0f6f4ca2010-06-09 10:26:26 -0700265endif # LOCAL_SDK_VERSION
The Android Open Source Project88b60792009-03-03 19:28:42 -0800266$(R_file_stamp): $(framework_res_package_export_deps)
Ying Wang0f6f4ca2010-06-09 10:26:26 -0700267$(LOCAL_INTERMEDIATE_TARGETS): \
268 PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
269endif # LOCAL_NO_STANDARD_LIBRARIES
The Android Open Source Project88b60792009-03-03 19:28:42 -0800270
271ifneq ($(full_classes_jar),)
272$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
273$(LOCAL_BUILT_MODULE): $(built_dex)
274endif # full_classes_jar
275
276
277# Get the list of jni libraries to be included in the apk file.
278
279so_suffix := $($(my_prefix)SHLIB_SUFFIX)
280
281jni_shared_libraries := \
282 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
283 $(addsuffix $(so_suffix), \
284 $(LOCAL_JNI_SHARED_LIBRARIES)))
285
Jack Palevicha0ab29b2010-06-18 15:38:07 +0800286# Set the abi directory used by the local JNI shared libraries.
287# (Doesn't change how the local shared libraries are compiled, just
288# sets where they are stored in the apk.)
289
290ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),)
291 jni_shared_libraries_abi := $(TARGET_CPU_ABI)
292else
293 jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI)
294endif
295
The Android Open Source Project88b60792009-03-03 19:28:42 -0800296# Pick a key to sign the package with. If this package hasn't specified
297# an explicit certificate, use the default.
298# Secure release builds will have their packages signed after the fact,
299# so it's ok for these private keys to be in the clear.
300ifeq ($(LOCAL_CERTIFICATE),)
301 LOCAL_CERTIFICATE := testkey
302endif
Doug Zongkerf6a53aa2009-12-15 15:06:55 -0800303
304ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
305 # The special value "EXTERNAL" means that we will sign it with the
306 # default testkey, apply predexopt, but then expect the final .apk
307 # (after dexopting) to be signed by an outside tool.
308 LOCAL_CERTIFICATE := testkey
309 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
310endif
311
The Android Open Source Project88b60792009-03-03 19:28:42 -0800312# If this is not an absolute certificate, assign it to a generic one.
313ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
314 LOCAL_CERTIFICATE := $(SRC_TARGET_DIR)/product/security/$(LOCAL_CERTIFICATE)
315endif
316private_key := $(LOCAL_CERTIFICATE).pk8
317certificate := $(LOCAL_CERTIFICATE).x509.pem
318
319$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
320$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
321$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
322
323PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
324PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
325
326# Define the rule to build the actual package.
327$(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN)
Ying Wange7874c42010-09-17 16:36:06 -0700328ifeq ($(LOCAL_DEX_PREOPT),true)
329# Make sure the boot jars get dexpreopt-ed first
330$(LOCAL_BUILT_MODULE): $(DEXPREOPT_BOOT_ODEXS) | $(DEXPREOPT) $(DEXOPT)
331endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800332$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries)
Jack Palevicha0ab29b2010-06-18 15:38:07 +0800333$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abi)
Joe Onorato16fa4b22010-06-09 16:35:58 -0700334ifneq ($(TARGET_BUILD_APPS),)
Ying Wang52911302010-05-26 13:13:56 -0700335 # Include all resources for unbundled apps.
Ying Wang8b07ed82010-12-28 13:14:29 -0800336 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
337endif
338ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
Ying Wang52911302010-05-26 13:13:56 -0700339 $(LOCAL_BUILT_MODULE): PRODUCT_AAPT_CONFIG :=
340endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800341$(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest)
342 @echo "target Package: $(PRIVATE_MODULE) ($@)"
343 $(create-empty-package)
344 $(add-assets-to-package)
345ifneq ($(jni_shared_libraries),)
346 $(add-jni-shared-libs-to-package)
347endif
348ifneq ($(full_classes_jar),)
349 $(add-dex-to-package)
350endif
351 $(sign-package)
352 @# Alignment must happen after all other zip operations.
353 $(align-package)
Ying Wange7874c42010-09-17 16:36:06 -0700354ifeq ($(LOCAL_DEX_PREOPT),true)
355 $(hide) rm -f $(patsubst %.apk,%.odex,$@)
356 $(call dexpreopt-one-file,$@,$(patsubst %.apk,%.odex,$@))
357 $(call dexpreopt-remove-classes.dex,$@)
358
359built_odex := $(basename $(LOCAL_BUILT_MODULE)).odex
360$(built_odex): $(LOCAL_BUILT_MODULE)
361endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800362
363# Save information about this package
364PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
365PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
366
367PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
Joe Onorato899e62a2010-02-04 17:37:21 -0800368
369endif # skip_definition