blob: 2ee399680b7c9b767ffcc0ef9f75ff8ae13d28fb [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
28LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME))
29ifeq ($(LOCAL_PACKAGE_NAME),)
30$(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
31endif
32
The Android Open Source Project88b60792009-03-03 19:28:42 -080033ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
34$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX)
35endif
36LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
37
38ifneq ($(strip $(LOCAL_MODULE)),)
39$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE)
40endif
41LOCAL_MODULE := $(LOCAL_PACKAGE_NAME)
42
43# Android packages should use Android resources or assets.
44ifneq (,$(LOCAL_JAVA_RESOURCE_DIRS))
45$(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_DIRS)
46endif
47ifneq (,$(LOCAL_JAVA_RESOURCE_FILES))
48$(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_FILES)
49endif
50
51ifneq ($(strip $(LOCAL_MODULE_CLASS)),)
52$(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS)
53endif
54LOCAL_MODULE_CLASS := APPS
55
The Android Open Source Project2f312932009-03-09 11:52:11 -070056# Package LOCAL_MODULE_TAGS default to optional
57LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
58ifeq ($(LOCAL_MODULE_TAGS),)
59LOCAL_MODULE_TAGS := optional
60endif
61
62#$(warning $(LOCAL_PATH) $(LOCAL_PACKAGE_NAME) $(sort $(LOCAL_MODULE_TAGS)))
63
The Android Open Source Project88b60792009-03-03 19:28:42 -080064ifeq (,$(LOCAL_ASSET_DIR))
65LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
66endif
67
68ifeq (,$(LOCAL_RESOURCE_DIR))
69 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
70endif
71LOCAL_RESOURCE_DIR := \
Bjorn Bringerta7ab17d2010-01-14 17:33:44 +000072 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
73 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
74 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
75 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -080076 $(LOCAL_RESOURCE_DIR)
77
78# this is an app, so add the system libraries to the search path
79LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
80
81#$(warning Finding assets for $(LOCAL_ASSET_DIR))
82
83all_assets := $(call find-subdir-assets,$(LOCAL_ASSET_DIR))
84all_assets := $(addprefix $(LOCAL_ASSET_DIR)/,$(patsubst assets/%,%,$(all_assets)))
85
86all_resources := $(strip \
87 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
88 $(addprefix $(dir)/, \
89 $(patsubst res/%,%, \
90 $(call find-subdir-assets,$(dir)) \
91 ) \
92 ) \
93 ))
94
95all_res_assets := $(strip $(all_assets) $(all_resources))
96
Ying Wang6ef046c2009-12-07 18:14:00 -080097package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -080098# If no assets or resources were found, clear the directory variables so
99# we don't try to build them.
100ifeq (,$(all_assets))
101LOCAL_ASSET_DIR:=
102endif
103ifeq (,$(all_resources))
104LOCAL_RESOURCE_DIR:=
105R_file_stamp :=
106else
107# Make sure that R_file_stamp inherits the proper PRIVATE vars.
108# If R.stamp moves, be sure to update the framework makefile,
109# which has intimate knowledge of its location.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800110R_file_stamp := $(package_expected_intermediates_COMMON)/src/R.stamp
111LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
112endif
113
114LOCAL_BUILT_MODULE_STEM := package.apk
115
Joe Onorato2daa2b32009-08-30 13:39:24 -0700116proguard_options_file := $(package_expected_intermediates_COMMON)/proguard_options
117ifneq ($(strip $(LOCAL_PROGUARD_ENABLED)),custom)
118 LOCAL_PROGUARD_FLAGS := -include $(proguard_options_file) $(LOCAL_PROGUARD_FLAGS)
119endif
120
The Android Open Source Project88b60792009-03-03 19:28:42 -0800121# The dex files go in the package, so we don't
122# want to install them separately for this module.
123old_DONT_INSTALL_DEX_FILES := $(DONT_INSTALL_DEX_FILES)
124DONT_INSTALL_DEX_FILES := true
125#################################
126include $(BUILD_SYSTEM)/java.mk
127#################################
128DONT_INSTALL_DEX_FILES := $(old_DONT_INSTALL_DEX_FILES)
129old_DONT_INSTALL_DEX_FILES =
130
131full_android_manifest := $(LOCAL_PATH)/AndroidManifest.xml
132$(LOCAL_INTERMEDIATE_TARGETS): \
133 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
134
135ifneq ($(all_resources),)
136
137# Since we don't know where the real R.java file is going to end up,
138# we need to use another file to stand in its place. We'll just
139# copy the generated file to src/R.stamp, which means it will
140# have the same contents and timestamp as the actual file.
141#
142# At the same time, this will copy the R.java file to a central
143# 'R' directory to make it easier to add the files to an IDE.
144#
145#TODO: use PRIVATE_SOURCE_INTERMEDIATES_DIR instead of
146# $(intermediates.COMMON)/src
147ifneq ($(package_expected_intermediates_COMMON),$(intermediates.COMMON))
148 $(error $(LOCAL_MODULE): internal error: expected intermediates.COMMON "$(package_expected_intermediates_COMMON)" != intermediates.COMMON "$(intermediates.COMMON)")
149endif
150
151$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
152 $(intermediates.COMMON)/public_resources.xml
Joe Onorato2daa2b32009-08-30 13:39:24 -0700153$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800154$(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(AAPT) | $(ACP)
155 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
156 @rm -f $@
157 $(create-resource-java-files)
158 $(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
159 -name Manifest.java 2> /dev/null`; do \
160 dir=`grep package $$GENERATED_MANIFEST_FILE | head -n1 | \
161 awk '{print $$2}' | tr -d ";" | tr . /`; \
162 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
163 $(ACP) -fpt $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
164 done;
165 $(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
166 -name R.java 2> /dev/null`; do \
167 dir=`grep package $$GENERATED_R_FILE | head -n1 | \
168 awk '{print $$2}' | tr -d ";" | tr . /`; \
169 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
170 $(ACP) -fpt $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
171 || exit 31; \
172 $(ACP) -fpt $$GENERATED_R_FILE $@ || exit 32; \
173 done; \
174
Joe Onorato2daa2b32009-08-30 13:39:24 -0700175$(proguard_options_file): $(R_file_stamp)
176
The Android Open Source Project88b60792009-03-03 19:28:42 -0800177ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
178# Put this module's resources into a PRODUCT-agnositc package that
179# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
180# files.
181resource_export_package := $(intermediates.COMMON)/package-export.apk
182$(R_file_stamp): $(resource_export_package)
183
184# add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
185# can't know anything about PRODUCT. Clear it out just for this target.
186$(resource_export_package): PRODUCT_AAPT_CONFIG :=
187$(resource_export_package): $(all_res_assets) $(full_android_manifest) $(AAPT)
188 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
189 $(create-empty-package)
190 $(add-assets-to-package)
191endif
192
193# Other modules should depend on the BUILT module if
194# they want to use this module's R.java file.
195$(LOCAL_BUILT_MODULE): $(R_file_stamp)
196
197ifneq ($(full_classes_jar),)
198# If full_classes_jar is non-empty, we're building sources.
199# If we're building sources, the initial javac step (which
200# produces full_classes_compiled_jar) needs to ensure the
201# R.java and Manifest.java files have been generated first.
202$(full_classes_compiled_jar): $(R_file_stamp)
203endif
204
205endif # all_resources
206
207ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
208# We need to explicitly clear this var so that we don't
209# inherit the value from whomever caused us to be built.
210$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
211else
212# Most packages should link against the resources defined by framework-res.
213# Even if they don't have their own resources, they may use framework
214# resources.
215framework_res_package_export := \
216 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
217$(LOCAL_INTERMEDIATE_TARGETS): \
218 PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
219# We can't depend directly on the export.apk file; it won't get its
220# PRIVATE_ vars set up correctly if we do. Instead, depend on the
221# corresponding R.stamp file, which lists the export.apk as a dependency.
222framework_res_package_export_deps := \
223 $(dir $(framework_res_package_export))src/R.stamp
224$(R_file_stamp): $(framework_res_package_export_deps)
225endif
226
227ifneq ($(full_classes_jar),)
228$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
229$(LOCAL_BUILT_MODULE): $(built_dex)
230endif # full_classes_jar
231
232
233# Get the list of jni libraries to be included in the apk file.
234
235so_suffix := $($(my_prefix)SHLIB_SUFFIX)
236
237jni_shared_libraries := \
238 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
239 $(addsuffix $(so_suffix), \
240 $(LOCAL_JNI_SHARED_LIBRARIES)))
241
242# Pick a key to sign the package with. If this package hasn't specified
243# an explicit certificate, use the default.
244# Secure release builds will have their packages signed after the fact,
245# so it's ok for these private keys to be in the clear.
246ifeq ($(LOCAL_CERTIFICATE),)
247 LOCAL_CERTIFICATE := testkey
248endif
Doug Zongkerf6a53aa2009-12-15 15:06:55 -0800249
250ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
251 # The special value "EXTERNAL" means that we will sign it with the
252 # default testkey, apply predexopt, but then expect the final .apk
253 # (after dexopting) to be signed by an outside tool.
254 LOCAL_CERTIFICATE := testkey
255 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
256endif
257
The Android Open Source Project88b60792009-03-03 19:28:42 -0800258# If this is not an absolute certificate, assign it to a generic one.
259ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
260 LOCAL_CERTIFICATE := $(SRC_TARGET_DIR)/product/security/$(LOCAL_CERTIFICATE)
261endif
262private_key := $(LOCAL_CERTIFICATE).pk8
263certificate := $(LOCAL_CERTIFICATE).x509.pem
264
265$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
266$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
267$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
268
269PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
270PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
271
272# Define the rule to build the actual package.
273$(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN)
274$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries)
275$(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest)
276 @echo "target Package: $(PRIVATE_MODULE) ($@)"
277 $(create-empty-package)
278 $(add-assets-to-package)
279ifneq ($(jni_shared_libraries),)
280 $(add-jni-shared-libs-to-package)
281endif
282ifneq ($(full_classes_jar),)
283 $(add-dex-to-package)
284endif
285 $(sign-package)
286 @# Alignment must happen after all other zip operations.
287 $(align-package)
288
289# Save information about this package
290PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
291PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
292
293PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)