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 ###########################################################
29 # If this makefile is being read from within an inheritance,
32 ifdef LOCAL_PACKAGE_OVERRIDES
33 package_overridden := $(call set-inherited-package-variables)
34 ifeq ($(strip $(package_overridden)),)
35 skip_definition := true
39 ifndef skip_definition
41 LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME))
42 ifeq ($(LOCAL_PACKAGE_NAME),)
43 $(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
46 ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
47 $(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX)
49 LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
51 ifneq ($(strip $(LOCAL_MODULE)),)
52 $(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE)
54 LOCAL_MODULE := $(LOCAL_PACKAGE_NAME)
56 # Android packages should use Android resources or assets.
57 ifneq (,$(LOCAL_JAVA_RESOURCE_DIRS))
58 $(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_DIRS)
60 ifneq (,$(LOCAL_JAVA_RESOURCE_FILES))
61 $(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_FILES)
64 ifneq ($(strip $(LOCAL_MODULE_CLASS)),)
65 $(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS)
67 LOCAL_MODULE_CLASS := APPS
69 # Package LOCAL_MODULE_TAGS default to optional
70 LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
71 ifeq ($(LOCAL_MODULE_TAGS),)
72 LOCAL_MODULE_TAGS := optional
75 #$(warning $(LOCAL_PATH) $(LOCAL_PACKAGE_NAME) $(sort $(LOCAL_MODULE_TAGS)))
77 ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),)
78 # Force localization check if it's not tagged as tests.
79 LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z
82 ifeq (,$(LOCAL_ASSET_DIR))
83 LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
86 ifeq (,$(LOCAL_RESOURCE_DIR))
87 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
89 LOCAL_RESOURCE_DIR := \
90 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
91 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
92 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
93 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
96 # this is an app, so add the system libraries to the search path
97 LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
99 #$(warning Finding assets for $(LOCAL_ASSET_DIR))
101 all_assets := $(call find-subdir-assets,$(LOCAL_ASSET_DIR))
102 all_assets := $(addprefix $(LOCAL_ASSET_DIR)/,$(patsubst assets/%,%,$(all_assets)))
104 all_resources := $(strip \
105 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
106 $(addprefix $(dir)/, \
107 $(patsubst res/%,%, \
108 $(call find-subdir-assets,$(dir)) \
113 all_res_assets := $(strip $(all_assets) $(all_resources))
115 package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
116 # If no assets or resources were found, clear the directory variables so
117 # we don't try to build them.
118 ifeq (,$(all_assets))
121 ifeq (,$(all_resources))
125 # Make sure that R_file_stamp inherits the proper PRIVATE vars.
126 # If R.stamp moves, be sure to update the framework makefile,
127 # which has intimate knowledge of its location.
128 R_file_stamp := $(package_expected_intermediates_COMMON)/src/R.stamp
129 LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
132 LOCAL_BUILT_MODULE_STEM := package.apk
134 LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
135 ifndef LOCAL_PROGUARD_ENABLED
136 ifneq ($(filter user userdebug, $(TARGET_BUILD_VARIANT)),)
137 # turn on Proguard by default for user & userdebug build
138 LOCAL_PROGUARD_ENABLED :=full
141 ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
142 # the package explicitly request to disable proguard.
143 LOCAL_PROGUARD_ENABLED :=
145 proguard_options_file :=
146 ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
147 ifneq ($(all_resources),)
148 proguard_options_file := $(package_expected_intermediates_COMMON)/proguard_options
149 endif # all_resources
151 LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
153 # The dex files go in the package, so we don't
154 # want to install them separately for this module.
155 old_DONT_INSTALL_DEX_FILES := $(DONT_INSTALL_DEX_FILES)
156 DONT_INSTALL_DEX_FILES := true
157 #################################
158 include $(BUILD_SYSTEM)/java.mk
159 #################################
160 DONT_INSTALL_DEX_FILES := $(old_DONT_INSTALL_DEX_FILES)
161 old_DONT_INSTALL_DEX_FILES =
163 full_android_manifest := $(LOCAL_PATH)/AndroidManifest.xml
164 $(LOCAL_INTERMEDIATE_TARGETS): \
165 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
167 ifneq ($(all_resources),)
169 # Since we don't know where the real R.java file is going to end up,
170 # we need to use another file to stand in its place. We'll just
171 # copy the generated file to src/R.stamp, which means it will
172 # have the same contents and timestamp as the actual file.
174 # At the same time, this will copy the R.java file to a central
175 # 'R' directory to make it easier to add the files to an IDE.
177 #TODO: use PRIVATE_SOURCE_INTERMEDIATES_DIR instead of
178 # $(intermediates.COMMON)/src
179 ifneq ($(package_expected_intermediates_COMMON),$(intermediates.COMMON))
180 $(error $(LOCAL_MODULE): internal error: expected intermediates.COMMON "$(package_expected_intermediates_COMMON)" != intermediates.COMMON "$(intermediates.COMMON)")
183 $(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
184 $(intermediates.COMMON)/public_resources.xml
185 $(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
186 $(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(AAPT) | $(ACP)
187 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
189 $(create-resource-java-files)
190 $(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
191 -name Manifest.java 2> /dev/null`; do \
192 dir=`grep package $$GENERATED_MANIFEST_FILE | head -n1 | \
193 awk '{print $$2}' | tr -d ";" | tr . /`; \
194 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
195 $(ACP) -fpt $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
197 $(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
198 -name R.java 2> /dev/null`; do \
199 dir=`grep package $$GENERATED_R_FILE | head -n1 | \
200 awk '{print $$2}' | tr -d ";" | tr . /`; \
201 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
202 $(ACP) -fpt $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
204 $(ACP) -fpt $$GENERATED_R_FILE $@ || exit 32; \
207 $(proguard_options_file): $(R_file_stamp)
209 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
210 # Put this module's resources into a PRODUCT-agnositc package that
211 # other packages can use to build their own PRODUCT-agnostic R.java (etc.)
213 resource_export_package := $(intermediates.COMMON)/package-export.apk
214 $(R_file_stamp): $(resource_export_package)
216 # add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
217 # can't know anything about PRODUCT. Clear it out just for this target.
218 $(resource_export_package): PRODUCT_AAPT_CONFIG :=
219 $(resource_export_package): $(all_res_assets) $(full_android_manifest) $(AAPT)
220 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
221 $(create-empty-package)
222 $(add-assets-to-package)
225 # Other modules should depend on the BUILT module if
226 # they want to use this module's R.java file.
227 $(LOCAL_BUILT_MODULE): $(R_file_stamp)
229 ifneq ($(full_classes_jar),)
230 # If full_classes_jar is non-empty, we're building sources.
231 # If we're building sources, the initial javac step (which
232 # produces full_classes_compiled_jar) needs to ensure the
233 # R.java and Manifest.java files have been generated first.
234 $(full_classes_compiled_jar): $(R_file_stamp)
237 endif # all_resources
239 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
240 # We need to explicitly clear this var so that we don't
241 # inherit the value from whomever caused us to be built.
242 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
244 # Most packages should link against the resources defined by framework-res.
245 # Even if they don't have their own resources, they may use framework
247 ifneq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
248 # for released sdk versions, the platform resources were built into android.jar.
249 framework_res_package_export := \
250 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/android.jar
251 framework_res_package_export_deps := $(framework_res_package_export)
252 else # LOCAL_SDK_VERSION
253 framework_res_package_export := \
254 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
255 # We can't depend directly on the export.apk file; it won't get its
256 # PRIVATE_ vars set up correctly if we do. Instead, depend on the
257 # corresponding R.stamp file, which lists the export.apk as a dependency.
258 framework_res_package_export_deps := \
259 $(dir $(framework_res_package_export))src/R.stamp
260 endif # LOCAL_SDK_VERSION
261 $(R_file_stamp): $(framework_res_package_export_deps)
262 $(LOCAL_INTERMEDIATE_TARGETS): \
263 PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
264 endif # LOCAL_NO_STANDARD_LIBRARIES
266 ifneq ($(full_classes_jar),)
267 $(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
268 $(LOCAL_BUILT_MODULE): $(built_dex)
269 endif # full_classes_jar
272 # Get the list of jni libraries to be included in the apk file.
274 so_suffix := $($(my_prefix)SHLIB_SUFFIX)
276 jni_shared_libraries := \
277 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
278 $(addsuffix $(so_suffix), \
279 $(LOCAL_JNI_SHARED_LIBRARIES)))
281 # Pick a key to sign the package with. If this package hasn't specified
282 # an explicit certificate, use the default.
283 # Secure release builds will have their packages signed after the fact,
284 # so it's ok for these private keys to be in the clear.
285 ifeq ($(LOCAL_CERTIFICATE),)
286 LOCAL_CERTIFICATE := testkey
289 ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
290 # The special value "EXTERNAL" means that we will sign it with the
291 # default testkey, apply predexopt, but then expect the final .apk
292 # (after dexopting) to be signed by an outside tool.
293 LOCAL_CERTIFICATE := testkey
294 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
297 # If this is not an absolute certificate, assign it to a generic one.
298 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
299 LOCAL_CERTIFICATE := $(SRC_TARGET_DIR)/product/security/$(LOCAL_CERTIFICATE)
301 private_key := $(LOCAL_CERTIFICATE).pk8
302 certificate := $(LOCAL_CERTIFICATE).x509.pem
304 $(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
305 $(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
306 $(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
308 PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
309 PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
311 # Define the rule to build the actual package.
312 $(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN)
313 $(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries)
314 ifneq ($(TARGET_BUILD_APPS),)
315 # Include all resources for unbundled apps.
316 $(LOCAL_BUILT_MODULE): PRODUCT_AAPT_CONFIG :=
318 $(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest)
319 @echo "target Package: $(PRIVATE_MODULE) ($@)"
320 $(create-empty-package)
321 $(add-assets-to-package)
322 ifneq ($(jni_shared_libraries),)
323 $(add-jni-shared-libs-to-package)
325 ifneq ($(full_classes_jar),)
326 $(add-dex-to-package)
329 @# Alignment must happen after all other zip operations.
332 # Save information about this package
333 PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
334 PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
336 PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
338 endif # skip_definition