2 # Copyright (C) 2008 The Android Open Source Project
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 ###########################################################
18 ## Standard rules for building an application package.
20 ## Additional inputs from base_rules.make:
21 ## LOCAL_PACKAGE_NAME: The name of the package; the directory
22 ## will be called this.
24 ## MODULE, MODULE_PATH, and MODULE_SUFFIX will
26 ###########################################################
28 LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME))
29 ifeq ($(LOCAL_PACKAGE_NAME),)
30 $(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
33 ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
34 $(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX)
36 LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
38 ifneq ($(strip $(LOCAL_MODULE)),)
39 $(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE)
41 LOCAL_MODULE := $(LOCAL_PACKAGE_NAME)
43 # Android packages should use Android resources or assets.
44 ifneq (,$(LOCAL_JAVA_RESOURCE_DIRS))
45 $(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_DIRS)
47 ifneq (,$(LOCAL_JAVA_RESOURCE_FILES))
48 $(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_FILES)
51 ifneq ($(strip $(LOCAL_MODULE_CLASS)),)
52 $(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS)
54 LOCAL_MODULE_CLASS := APPS
56 # Package LOCAL_MODULE_TAGS default to optional
57 LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
58 ifeq ($(LOCAL_MODULE_TAGS),)
59 LOCAL_MODULE_TAGS := optional
62 #$(warning $(LOCAL_PATH) $(LOCAL_PACKAGE_NAME) $(sort $(LOCAL_MODULE_TAGS)))
64 ifeq (,$(LOCAL_ASSET_DIR))
65 LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
68 ifeq (,$(LOCAL_RESOURCE_DIR))
69 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
71 LOCAL_RESOURCE_DIR := \
72 $(wildcard $(addsuffix /$(LOCAL_RESOURCE_DIR), $(PRODUCT_PACKAGE_OVERLAYS))) \
73 $(wildcard $(addsuffix /$(LOCAL_RESOURCE_DIR), $(DEVICE_PACKAGE_OVERLAYS))) \
76 # this is an app, so add the system libraries to the search path
77 LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
79 #$(warning Finding assets for $(LOCAL_ASSET_DIR))
81 all_assets := $(call find-subdir-assets,$(LOCAL_ASSET_DIR))
82 all_assets := $(addprefix $(LOCAL_ASSET_DIR)/,$(patsubst assets/%,%,$(all_assets)))
84 all_resources := $(strip \
85 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
86 $(addprefix $(dir)/, \
88 $(call find-subdir-assets,$(dir)) \
93 all_res_assets := $(strip $(all_assets) $(all_resources))
95 package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
96 # If no assets or resources were found, clear the directory variables so
97 # we don't try to build them.
101 ifeq (,$(all_resources))
105 # Make sure that R_file_stamp inherits the proper PRIVATE vars.
106 # If R.stamp moves, be sure to update the framework makefile,
107 # which has intimate knowledge of its location.
108 R_file_stamp := $(package_expected_intermediates_COMMON)/src/R.stamp
109 LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
112 LOCAL_BUILT_MODULE_STEM := package.apk
114 proguard_options_file := $(package_expected_intermediates_COMMON)/proguard_options
115 ifneq ($(strip $(LOCAL_PROGUARD_ENABLED)),custom)
116 LOCAL_PROGUARD_FLAGS := -include $(proguard_options_file) $(LOCAL_PROGUARD_FLAGS)
119 # The dex files go in the package, so we don't
120 # want to install them separately for this module.
121 old_DONT_INSTALL_DEX_FILES := $(DONT_INSTALL_DEX_FILES)
122 DONT_INSTALL_DEX_FILES := true
123 #################################
124 include $(BUILD_SYSTEM)/java.mk
125 #################################
126 DONT_INSTALL_DEX_FILES := $(old_DONT_INSTALL_DEX_FILES)
127 old_DONT_INSTALL_DEX_FILES =
129 full_android_manifest := $(LOCAL_PATH)/AndroidManifest.xml
130 $(LOCAL_INTERMEDIATE_TARGETS): \
131 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
133 ifneq ($(all_resources),)
135 # Since we don't know where the real R.java file is going to end up,
136 # we need to use another file to stand in its place. We'll just
137 # copy the generated file to src/R.stamp, which means it will
138 # have the same contents and timestamp as the actual file.
140 # At the same time, this will copy the R.java file to a central
141 # 'R' directory to make it easier to add the files to an IDE.
143 #TODO: use PRIVATE_SOURCE_INTERMEDIATES_DIR instead of
144 # $(intermediates.COMMON)/src
145 ifneq ($(package_expected_intermediates_COMMON),$(intermediates.COMMON))
146 $(error $(LOCAL_MODULE): internal error: expected intermediates.COMMON "$(package_expected_intermediates_COMMON)" != intermediates.COMMON "$(intermediates.COMMON)")
149 $(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
150 $(intermediates.COMMON)/public_resources.xml
151 $(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
152 $(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(AAPT) | $(ACP)
153 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
155 $(create-resource-java-files)
156 $(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
157 -name Manifest.java 2> /dev/null`; do \
158 dir=`grep package $$GENERATED_MANIFEST_FILE | head -n1 | \
159 awk '{print $$2}' | tr -d ";" | tr . /`; \
160 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
161 $(ACP) -fpt $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
163 $(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
164 -name R.java 2> /dev/null`; do \
165 dir=`grep package $$GENERATED_R_FILE | head -n1 | \
166 awk '{print $$2}' | tr -d ";" | tr . /`; \
167 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
168 $(ACP) -fpt $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
170 $(ACP) -fpt $$GENERATED_R_FILE $@ || exit 32; \
173 $(proguard_options_file): $(R_file_stamp)
175 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
176 # Put this module's resources into a PRODUCT-agnositc package that
177 # other packages can use to build their own PRODUCT-agnostic R.java (etc.)
179 resource_export_package := $(intermediates.COMMON)/package-export.apk
180 $(R_file_stamp): $(resource_export_package)
182 # add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
183 # can't know anything about PRODUCT. Clear it out just for this target.
184 $(resource_export_package): PRODUCT_AAPT_CONFIG :=
185 $(resource_export_package): $(all_res_assets) $(full_android_manifest) $(AAPT)
186 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
187 $(create-empty-package)
188 $(add-assets-to-package)
191 # Other modules should depend on the BUILT module if
192 # they want to use this module's R.java file.
193 $(LOCAL_BUILT_MODULE): $(R_file_stamp)
195 ifneq ($(full_classes_jar),)
196 # If full_classes_jar is non-empty, we're building sources.
197 # If we're building sources, the initial javac step (which
198 # produces full_classes_compiled_jar) needs to ensure the
199 # R.java and Manifest.java files have been generated first.
200 $(full_classes_compiled_jar): $(R_file_stamp)
203 endif # all_resources
205 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
206 # We need to explicitly clear this var so that we don't
207 # inherit the value from whomever caused us to be built.
208 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
210 # Most packages should link against the resources defined by framework-res.
211 # Even if they don't have their own resources, they may use framework
213 framework_res_package_export := \
214 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
215 $(LOCAL_INTERMEDIATE_TARGETS): \
216 PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
217 # We can't depend directly on the export.apk file; it won't get its
218 # PRIVATE_ vars set up correctly if we do. Instead, depend on the
219 # corresponding R.stamp file, which lists the export.apk as a dependency.
220 framework_res_package_export_deps := \
221 $(dir $(framework_res_package_export))src/R.stamp
222 $(R_file_stamp): $(framework_res_package_export_deps)
225 ifneq ($(full_classes_jar),)
226 $(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
227 $(LOCAL_BUILT_MODULE): $(built_dex)
228 endif # full_classes_jar
231 # Get the list of jni libraries to be included in the apk file.
233 so_suffix := $($(my_prefix)SHLIB_SUFFIX)
235 jni_shared_libraries := \
236 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
237 $(addsuffix $(so_suffix), \
238 $(LOCAL_JNI_SHARED_LIBRARIES)))
240 # Pick a key to sign the package with. If this package hasn't specified
241 # an explicit certificate, use the default.
242 # Secure release builds will have their packages signed after the fact,
243 # so it's ok for these private keys to be in the clear.
244 ifeq ($(LOCAL_CERTIFICATE),)
245 LOCAL_CERTIFICATE := testkey
247 # If this is not an absolute certificate, assign it to a generic one.
248 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
249 LOCAL_CERTIFICATE := $(SRC_TARGET_DIR)/product/security/$(LOCAL_CERTIFICATE)
251 private_key := $(LOCAL_CERTIFICATE).pk8
252 certificate := $(LOCAL_CERTIFICATE).x509.pem
254 $(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
255 $(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
256 $(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
258 PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
259 PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
261 # Define the rule to build the actual package.
262 $(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN)
263 $(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries)
264 $(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest)
265 @echo "target Package: $(PRIVATE_MODULE) ($@)"
266 $(create-empty-package)
267 $(add-assets-to-package)
268 ifneq ($(jni_shared_libraries),)
269 $(add-jni-shared-libs-to-package)
271 ifneq ($(full_classes_jar),)
272 $(add-dex-to-package)
275 @# Alignment must happen after all other zip operations.
278 # Save information about this package
279 PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
280 PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
282 PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)