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