Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 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 | # If this makefile is being read from within an inheritance, |
| 29 | # use the new values. |
| 30 | skip_definition:= |
| 31 | ifdef LOCAL_PACKAGE_OVERRIDES |
| 32 | package_overridden := $(call set-inherited-package-variables) |
| 33 | ifeq ($(strip $(package_overridden)),) |
| 34 | skip_definition := true |
| 35 | endif |
| 36 | endif |
| 37 | |
| 38 | ifndef skip_definition |
| 39 | |
| 40 | LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME)) |
| 41 | ifeq ($(LOCAL_PACKAGE_NAME),) |
| 42 | $(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME) |
| 43 | endif |
| 44 | |
| 45 | ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),) |
| 46 | $(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX) |
| 47 | endif |
| 48 | LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) |
| 49 | |
| 50 | ifneq ($(strip $(LOCAL_MODULE)),) |
| 51 | $(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE) |
| 52 | endif |
| 53 | LOCAL_MODULE := $(LOCAL_PACKAGE_NAME) |
| 54 | |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 55 | ifneq ($(strip $(LOCAL_MODULE_CLASS)),) |
| 56 | $(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS) |
| 57 | endif |
| 58 | LOCAL_MODULE_CLASS := APPS |
| 59 | |
| 60 | # Package LOCAL_MODULE_TAGS default to optional |
| 61 | LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS)) |
| 62 | ifeq ($(LOCAL_MODULE_TAGS),) |
| 63 | LOCAL_MODULE_TAGS := optional |
| 64 | endif |
| 65 | |
| 66 | ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),) |
| 67 | # Force localization check if it's not tagged as tests. |
| 68 | LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z |
| 69 | endif |
| 70 | |
Ying Wang | 1425e2d | 2014-07-22 15:42:11 -0700 | [diff] [blame] | 71 | ifdef LOCAL_PACKAGE_SPLITS |
| 72 | LOCAL_AAPT_FLAGS += $(addprefix --split ,$(LOCAL_PACKAGE_SPLITS)) |
| 73 | endif |
| 74 | |
Ying Wang | bfcdf06 | 2014-07-29 10:34:30 -0700 | [diff] [blame] | 75 | need_compile_asset := |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 76 | ifeq (,$(LOCAL_ASSET_DIR)) |
| 77 | LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets |
Ying Wang | bfcdf06 | 2014-07-29 10:34:30 -0700 | [diff] [blame] | 78 | else |
| 79 | need_compile_asset := true |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 80 | endif |
| 81 | |
Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 82 | # LOCAL_RESOURCE_DIR may point to resource generated during the build |
| 83 | need_compile_res := |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 84 | ifeq (,$(LOCAL_RESOURCE_DIR)) |
| 85 | LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res |
Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 86 | else |
| 87 | need_compile_res := true |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 88 | endif |
| 89 | |
| 90 | package_resource_overlays := $(strip \ |
| 91 | $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \ |
| 92 | $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \ |
| 93 | $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \ |
| 94 | $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR))))) |
| 95 | |
| 96 | LOCAL_RESOURCE_DIR := $(package_resource_overlays) $(LOCAL_RESOURCE_DIR) |
| 97 | |
Colin Cross | 2c32144 | 2014-02-12 13:06:30 -0800 | [diff] [blame] | 98 | all_assets := $(strip \ |
| 99 | $(foreach dir, $(LOCAL_ASSET_DIR), \ |
| 100 | $(addprefix $(dir)/, \ |
| 101 | $(patsubst assets/%,%, \ |
| 102 | $(call find-subdir-assets, $(dir)) \ |
| 103 | ) \ |
| 104 | ) \ |
| 105 | )) |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 106 | |
Ying Wang | bfcdf06 | 2014-07-29 10:34:30 -0700 | [diff] [blame] | 107 | ifneq ($(all_assets),) |
| 108 | need_compile_asset := true |
| 109 | endif |
| 110 | |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 111 | all_resources := $(strip \ |
| 112 | $(foreach dir, $(LOCAL_RESOURCE_DIR), \ |
| 113 | $(addprefix $(dir)/, \ |
| 114 | $(patsubst res/%,%, \ |
| 115 | $(call find-subdir-assets,$(dir)) \ |
| 116 | ) \ |
| 117 | ) \ |
| 118 | )) |
| 119 | |
Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 120 | ifneq ($(all_resources),) |
| 121 | need_compile_res := true |
| 122 | endif |
| 123 | |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 124 | all_res_assets := $(strip $(all_assets) $(all_resources)) |
| 125 | |
| 126 | package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON) |
| 127 | # If no assets or resources were found, clear the directory variables so |
| 128 | # we don't try to build them. |
Ying Wang | bfcdf06 | 2014-07-29 10:34:30 -0700 | [diff] [blame] | 129 | ifneq (true,$(need_compile_asset)) |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 130 | LOCAL_ASSET_DIR:= |
| 131 | endif |
Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 132 | ifneq (true,$(need_compile_res)) |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 133 | LOCAL_RESOURCE_DIR:= |
| 134 | R_file_stamp := |
| 135 | else |
| 136 | # Make sure that R_file_stamp inherits the proper PRIVATE vars. |
| 137 | # If R.stamp moves, be sure to update the framework makefile, |
| 138 | # which has intimate knowledge of its location. |
| 139 | R_file_stamp := $(package_expected_intermediates_COMMON)/src/R.stamp |
| 140 | LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp) |
| 141 | endif |
| 142 | |
| 143 | LOCAL_BUILT_MODULE_STEM := package.apk |
Ying Wang | af9757e | 2014-07-17 21:24:42 -0700 | [diff] [blame] | 144 | LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 145 | |
| 146 | LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED)) |
| 147 | ifndef LOCAL_PROGUARD_ENABLED |
| 148 | ifneq ($(DISABLE_PROGUARD),true) |
| 149 | LOCAL_PROGUARD_ENABLED :=full |
| 150 | endif |
| 151 | endif |
| 152 | ifeq ($(LOCAL_PROGUARD_ENABLED),disabled) |
| 153 | # the package explicitly request to disable proguard. |
| 154 | LOCAL_PROGUARD_ENABLED := |
| 155 | endif |
| 156 | proguard_options_file := |
| 157 | ifneq ($(LOCAL_PROGUARD_ENABLED),custom) |
Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 158 | ifeq ($(need_compile_res),true) |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 159 | proguard_options_file := $(package_expected_intermediates_COMMON)/proguard_options |
Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 160 | endif # need_compile_res |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 161 | endif # !custom |
| 162 | LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS) |
| 163 | |
| 164 | ifeq (true,$(EMMA_INSTRUMENT)) |
| 165 | ifndef LOCAL_EMMA_INSTRUMENT |
| 166 | # No emma for test apks. |
| 167 | ifeq (,$(filer tests,$(LOCAL_MODULE_TAGS))$(LOCAL_INSTRUMENTATION_FOR)) |
| 168 | LOCAL_EMMA_INSTRUMENT := true |
| 169 | endif # No test apk |
| 170 | endif # LOCAL_EMMA_INSTRUMENT is not set |
| 171 | else |
| 172 | LOCAL_EMMA_INSTRUMENT := false |
| 173 | endif # EMMA_INSTRUMENT is true |
| 174 | |
| 175 | ifeq (true,$(LOCAL_EMMA_INSTRUMENT)) |
| 176 | ifeq (true,$(EMMA_INSTRUMENT_STATIC)) |
| 177 | LOCAL_STATIC_JAVA_LIBRARIES += emma |
| 178 | else |
| 179 | ifdef LOCAL_SDK_VERSION |
| 180 | ifdef TARGET_BUILD_APPS |
| 181 | # In unbundled build merge the emma library into the apk. |
| 182 | LOCAL_STATIC_JAVA_LIBRARIES += emma |
| 183 | else |
| 184 | # If build against the SDK in full build, core.jar is not used, |
| 185 | # we have to use prebiult emma.jar to make Proguard happy; |
| 186 | # Otherwise emma classes are included in core.jar. |
| 187 | LOCAL_PROGUARD_FLAGS += -libraryjars $(EMMA_JAR) |
| 188 | endif # full build |
| 189 | endif # LOCAL_SDK_VERSION |
| 190 | endif # EMMA_INSTRUMENT_STATIC |
| 191 | endif # LOCAL_EMMA_INSTRUMENT |
| 192 | |
| 193 | rs_compatibility_jni_libs := |
| 194 | |
| 195 | ################################# |
| 196 | include $(BUILD_SYSTEM)/java.mk |
| 197 | ################################# |
| 198 | |
| 199 | LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) |
| 200 | ifeq ($(LOCAL_SDK_RES_VERSION),) |
| 201 | LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) |
| 202 | endif |
| 203 | |
Colin Cross | 2c32144 | 2014-02-12 13:06:30 -0800 | [diff] [blame] | 204 | include $(BUILD_SYSTEM)/android_manifest.mk |
| 205 | |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 206 | $(LOCAL_INTERMEDIATE_TARGETS): \ |
| 207 | PRIVATE_ANDROID_MANIFEST := $(full_android_manifest) |
Ying Wang | efb9358 | 2014-07-19 17:00:50 -0700 | [diff] [blame] | 208 | ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION))) |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 209 | $(LOCAL_INTERMEDIATE_TARGETS): \ |
| 210 | PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION) |
| 211 | else |
| 212 | $(LOCAL_INTERMEDIATE_TARGETS): \ |
| 213 | PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK) |
| 214 | endif |
| 215 | |
Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 216 | ifeq ($(need_compile_res),true) |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 217 | |
| 218 | # Since we don't know where the real R.java file is going to end up, |
| 219 | # we need to use another file to stand in its place. We'll just |
| 220 | # copy the generated file to src/R.stamp, which means it will |
| 221 | # have the same contents and timestamp as the actual file. |
| 222 | # |
| 223 | # At the same time, this will copy the R.java file to a central |
| 224 | # 'R' directory to make it easier to add the files to an IDE. |
| 225 | # |
| 226 | #TODO: use PRIVATE_SOURCE_INTERMEDIATES_DIR instead of |
| 227 | # $(intermediates.COMMON)/src |
| 228 | ifneq ($(package_expected_intermediates_COMMON),$(intermediates.COMMON)) |
| 229 | $(error $(LOCAL_MODULE): internal error: expected intermediates.COMMON "$(package_expected_intermediates_COMMON)" != intermediates.COMMON "$(intermediates.COMMON)") |
| 230 | endif |
| 231 | |
| 232 | $(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \ |
| 233 | $(intermediates.COMMON)/public_resources.xml |
| 234 | $(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file) |
| 235 | $(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT) | $(ACP) |
| 236 | @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)" |
| 237 | @rm -f $@ |
| 238 | $(create-resource-java-files) |
| 239 | $(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \ |
| 240 | -name Manifest.java 2> /dev/null`; do \ |
| 241 | dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_MANIFEST_FILE`; \ |
| 242 | mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \ |
| 243 | $(ACP) -fp $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \ |
| 244 | done; |
| 245 | $(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \ |
| 246 | -name R.java 2> /dev/null`; do \ |
| 247 | dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_R_FILE`; \ |
| 248 | mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \ |
| 249 | $(ACP) -fp $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \ |
| 250 | || exit 31; \ |
| 251 | $(ACP) -fp $$GENERATED_R_FILE $@ || exit 32; \ |
| 252 | done; \ |
| 253 | |
| 254 | $(proguard_options_file): $(R_file_stamp) |
| 255 | |
Ying Wang | dbe23f5 | 2014-03-25 14:42:46 -0700 | [diff] [blame] | 256 | resource_export_package := |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 257 | ifdef LOCAL_EXPORT_PACKAGE_RESOURCES |
| 258 | # Put this module's resources into a PRODUCT-agnositc package that |
| 259 | # other packages can use to build their own PRODUCT-agnostic R.java (etc.) |
| 260 | # files. |
| 261 | resource_export_package := $(intermediates.COMMON)/package-export.apk |
| 262 | $(R_file_stamp): $(resource_export_package) |
| 263 | |
| 264 | # add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target |
| 265 | # can't know anything about PRODUCT. Clear it out just for this target. |
| 266 | $(resource_export_package): PRIVATE_PRODUCT_AAPT_CONFIG := |
| 267 | $(resource_export_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := |
| 268 | $(resource_export_package): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_stamp) $(AAPT) |
| 269 | @echo "target Export Resources: $(PRIVATE_MODULE) ($@)" |
| 270 | $(create-empty-package) |
| 271 | $(add-assets-to-package) |
| 272 | endif |
| 273 | |
| 274 | # Other modules should depend on the BUILT module if |
| 275 | # they want to use this module's R.java file. |
| 276 | $(LOCAL_BUILT_MODULE): $(R_file_stamp) |
| 277 | |
| 278 | ifneq ($(full_classes_jar),) |
| 279 | # If full_classes_jar is non-empty, we're building sources. |
| 280 | # If we're building sources, the initial javac step (which |
| 281 | # produces full_classes_compiled_jar) needs to ensure the |
| 282 | # R.java and Manifest.java files have been generated first. |
| 283 | $(full_classes_compiled_jar): $(R_file_stamp) |
| 284 | endif |
| 285 | |
Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 286 | endif # need_compile_res |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 287 | |
| 288 | ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true) |
| 289 | # We need to explicitly clear this var so that we don't |
| 290 | # inherit the value from whomever caused us to be built. |
| 291 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES := |
| 292 | else |
| 293 | # Most packages should link against the resources defined by framework-res. |
| 294 | # Even if they don't have their own resources, they may use framework |
| 295 | # resources. |
Ying Wang | efb9358 | 2014-07-19 17:00:50 -0700 | [diff] [blame] | 296 | ifneq ($(filter-out current system_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current,$(LOCAL_SDK_RES_VERSION))),) |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 297 | # for released sdk versions, the platform resources were built into android.jar. |
| 298 | framework_res_package_export := \ |
| 299 | $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar |
| 300 | framework_res_package_export_deps := $(framework_res_package_export) |
| 301 | else # LOCAL_SDK_RES_VERSION |
| 302 | framework_res_package_export := \ |
| 303 | $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk |
| 304 | # We can't depend directly on the export.apk file; it won't get its |
| 305 | # PRIVATE_ vars set up correctly if we do. Instead, depend on the |
| 306 | # corresponding R.stamp file, which lists the export.apk as a dependency. |
| 307 | framework_res_package_export_deps := \ |
| 308 | $(dir $(framework_res_package_export))src/R.stamp |
| 309 | endif # LOCAL_SDK_RES_VERSION |
Adam Lesinski | de057c3 | 2014-03-13 18:48:27 -0700 | [diff] [blame] | 310 | all_library_res_package_exports := \ |
| 311 | $(framework_res_package_export) \ |
Adam Lesinski | 5eebe0f | 2014-03-25 15:45:34 -0700 | [diff] [blame] | 312 | $(foreach lib,$(LOCAL_RES_LIBRARIES),\ |
Adam Lesinski | de057c3 | 2014-03-13 18:48:27 -0700 | [diff] [blame] | 313 | $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk) |
| 314 | |
| 315 | all_library_res_package_export_deps := \ |
| 316 | $(framework_res_package_export_deps) \ |
Adam Lesinski | 5eebe0f | 2014-03-25 15:45:34 -0700 | [diff] [blame] | 317 | $(foreach lib,$(LOCAL_RES_LIBRARIES),\ |
Adam Lesinski | de057c3 | 2014-03-13 18:48:27 -0700 | [diff] [blame] | 318 | $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp) |
| 319 | |
Ying Wang | b574564 | 2014-06-19 16:07:30 -0700 | [diff] [blame] | 320 | $(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps) |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 321 | $(LOCAL_INTERMEDIATE_TARGETS): \ |
Adam Lesinski | de057c3 | 2014-03-13 18:48:27 -0700 | [diff] [blame] | 322 | PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports) |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 323 | endif # LOCAL_NO_STANDARD_LIBRARIES |
| 324 | |
| 325 | ifneq ($(full_classes_jar),) |
| 326 | $(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex) |
| 327 | $(LOCAL_BUILT_MODULE): $(built_dex) |
| 328 | endif # full_classes_jar |
| 329 | |
Ying Wang | 96bcad4 | 2014-04-17 13:38:04 -0700 | [diff] [blame] | 330 | include $(BUILD_SYSTEM)/install_jni_libs.mk |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 331 | |
| 332 | # Pick a key to sign the package with. If this package hasn't specified |
| 333 | # an explicit certificate, use the default. |
| 334 | # Secure release builds will have their packages signed after the fact, |
| 335 | # so it's ok for these private keys to be in the clear. |
| 336 | ifeq ($(LOCAL_CERTIFICATE),) |
| 337 | LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE) |
| 338 | endif |
| 339 | |
| 340 | ifeq ($(LOCAL_CERTIFICATE),EXTERNAL) |
| 341 | # The special value "EXTERNAL" means that we will sign it with the |
| 342 | # default devkey, apply predexopt, but then expect the final .apk |
| 343 | # (after dexopting) to be signed by an outside tool. |
| 344 | LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE) |
| 345 | PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1 |
| 346 | endif |
| 347 | |
| 348 | # If this is not an absolute certificate, assign it to a generic one. |
| 349 | ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./) |
| 350 | LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE) |
| 351 | endif |
| 352 | private_key := $(LOCAL_CERTIFICATE).pk8 |
| 353 | certificate := $(LOCAL_CERTIFICATE).x509.pem |
| 354 | |
| 355 | $(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR) |
| 356 | $(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key) |
| 357 | $(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate) |
| 358 | |
| 359 | PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key) |
| 360 | PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate) |
| 361 | |
| 362 | $(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(foreach c,\ |
| 363 | $(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8) |
| 364 | |
| 365 | # Define the rule to build the actual package. |
| 366 | $(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN) |
Ying Wang | 8e20ef6 | 2014-06-24 20:01:52 -0700 | [diff] [blame] | 367 | # PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>. |
| 368 | $(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis) |
| 369 | # PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names. |
| 370 | $(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis) |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 371 | ifneq ($(TARGET_BUILD_APPS),) |
| 372 | # Include all resources for unbundled apps. |
| 373 | LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true |
| 374 | endif |
| 375 | ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true) |
| 376 | $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := |
| 377 | $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := |
| 378 | else |
| 379 | $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG) |
Ying Wang | 934008f | 2014-07-30 13:40:14 -0700 | [diff] [blame] | 380 | ifdef LOCAL_PACKAGE_SPLITS |
| 381 | $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := |
| 382 | else |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 383 | $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG) |
| 384 | endif |
Ying Wang | 934008f | 2014-07-30 13:40:14 -0700 | [diff] [blame] | 385 | endif |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 386 | $(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest) |
| 387 | @echo "target Package: $(PRIVATE_MODULE) ($@)" |
| 388 | $(create-empty-package) |
| 389 | $(add-assets-to-package) |
| 390 | ifneq ($(jni_shared_libraries),) |
| 391 | $(add-jni-shared-libs-to-package) |
| 392 | endif |
| 393 | ifneq ($(full_classes_jar),) |
| 394 | $(add-dex-to-package) |
| 395 | endif |
| 396 | $(add-carried-java-resources) |
| 397 | ifneq ($(extra_jar_args),) |
| 398 | $(add-java-resources-to-package) |
| 399 | endif |
| 400 | $(sign-package) |
| 401 | ifdef LOCAL_DEX_PREOPT |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 402 | ifneq (nostripping,$(LOCAL_DEX_PREOPT)) |
| 403 | $(call dexpreopt-remove-classes.dex,$@) |
| 404 | endif |
| 405 | endif |
| 406 | @# Alignment must happen after all other zip operations. |
| 407 | $(align-package) |
| 408 | |
Ying Wang | 36142f6 | 2014-05-21 16:13:33 -0700 | [diff] [blame] | 409 | ############################### |
| 410 | ## Rule to build the odex file |
| 411 | ifdef LOCAL_DEX_PREOPT |
| 412 | $(built_odex): PRIVATE_DEX_FILE := $(built_dex) |
| 413 | $(built_odex) : $(built_dex) |
Ying Wang | 994c226 | 2014-05-28 13:34:59 -0700 | [diff] [blame] | 414 | $(hide) mkdir -p $(dir $@) && rm -f $@ |
Ying Wang | 36142f6 | 2014-05-21 16:13:33 -0700 | [diff] [blame] | 415 | $(add-dex-to-package) |
| 416 | $(hide) mv $@ $@.input |
| 417 | $(call dexpreopt-one-file,$@.input,$@) |
| 418 | $(hide) rm $@.input |
| 419 | endif |
| 420 | |
Ying Wang | 1425e2d | 2014-07-22 15:42:11 -0700 | [diff] [blame] | 421 | ############################### |
| 422 | ## APK splits |
| 423 | ifdef LOCAL_PACKAGE_SPLITS |
Ying Wang | 7f625aa | 2014-07-23 10:27:57 -0700 | [diff] [blame] | 424 | # LOCAL_PACKAGE_SPLITS is a list of resource labels. |
Ying Wang | 1425e2d | 2014-07-22 15:42:11 -0700 | [diff] [blame] | 425 | built_apk_splits := $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(built_module_path)/package_$(s).apk) |
| 426 | installed_apk_splits := $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk) |
| 427 | |
Ying Wang | 7f625aa | 2014-07-23 10:27:57 -0700 | [diff] [blame] | 428 | # The splits should have been built in the same command building the base apk. |
| 429 | # This rule just runs signing and zipalign etc. |
| 430 | # Note that we explicily check the existence of the split apk and remove the |
| 431 | # built base apk if the split apk isn't there. |
| 432 | # That way the build system will rerun the aapt after the user changes the splitting parameters. |
Ying Wang | 1425e2d | 2014-07-22 15:42:11 -0700 | [diff] [blame] | 433 | $(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key) |
| 434 | $(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate) |
Ying Wang | 7f625aa | 2014-07-23 10:27:57 -0700 | [diff] [blame] | 435 | $(built_apk_splits) : $(built_module_path)/%.apk : $(LOCAL_BUILT_MODULE) |
| 436 | $(hide) if [ ! -f $@ ]; then \ |
| 437 | echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \ |
| 438 | rm $<; exit 1; \ |
| 439 | fi |
| 440 | $(sign-package) |
| 441 | $(align-package) |
Ying Wang | 1425e2d | 2014-07-22 15:42:11 -0700 | [diff] [blame] | 442 | |
| 443 | # Rules to install the splits |
Ying Wang | 7f625aa | 2014-07-23 10:27:57 -0700 | [diff] [blame] | 444 | $(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(built_module_path)/package_%.apk | $(ACP) |
| 445 | @echo "Install: $@" |
| 446 | $(copy-file-to-new-target) |
Ying Wang | 1425e2d | 2014-07-22 15:42:11 -0700 | [diff] [blame] | 447 | |
| 448 | # Register the additional built and installed files. |
| 449 | ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits) |
| 450 | ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \ |
| 451 | $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(built_module_path)/package_$(s).apk:$(my_module_path)/$(LOCAL_MODULE)_$(s).apk) |
| 452 | |
| 453 | # Make sure to install the splits when you run "make <module_name>". |
| 454 | $(my_register_name): $(installed_apk_splits) |
| 455 | endif # LOCAL_PACKAGE_SPLITS |
| 456 | |
Colin Cross | 8e40412 | 2014-02-06 14:45:37 -0800 | [diff] [blame] | 457 | # Save information about this package |
| 458 | PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES)) |
| 459 | PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources) |
| 460 | ifdef package_resource_overlays |
| 461 | PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_OVERLAYS := $(package_resource_overlays) |
| 462 | endif |
| 463 | |
| 464 | PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME) |
| 465 | |
| 466 | # Dist the files that can be bundled in system.img. |
| 467 | # They include the jni shared libraries and the apk with jni libraries stripped. |
| 468 | ifeq ($(LOCAL_DIST_BUNDLED_BINARIES),true) |
| 469 | ifneq ($(filter $(LOCAL_PACKAGE_NAME),$(TARGET_BUILD_APPS)),) |
| 470 | ifneq ($(strip $(jni_shared_libraries)),) |
| 471 | dist_subdir := bundled_$(LOCAL_PACKAGE_NAME) |
| 472 | $(foreach f, $(jni_shared_libraries), \ |
| 473 | $(call dist-for-goals, apps_only, $(f):$(dist_subdir)/$(notdir $(f)))) |
| 474 | |
| 475 | apk_jni_stripped := $(intermediates)/jni_stripped/package.apk |
| 476 | $(apk_jni_stripped): PRIVATE_JNI_SHARED_LIBRARIES := $(notdir $(jni_shared_libraries)) |
| 477 | $(apk_jni_stripped) : $(LOCAL_BUILT_MODULE) | $(ZIPALIGN) |
| 478 | @rm -rf $(dir $@) && mkdir -p $(dir $@) |
| 479 | $(hide) cp $< $@ |
| 480 | $(hide) zip -d $@ $(foreach f,$(PRIVATE_JNI_SHARED_LIBRARIES),\*/$(f)) |
| 481 | $(call align-package) |
| 482 | |
| 483 | $(call dist-for-goals, apps_only, $(apk_jni_stripped):$(dist_subdir)/$(LOCAL_PACKAGE_NAME).apk) |
| 484 | |
| 485 | endif # jni_shared_libraries |
| 486 | endif # apps_only build |
| 487 | endif # LOCAL_DIST_BUNDLED_BINARIES |
| 488 | |
| 489 | # Lint phony targets |
| 490 | .PHONY: lint-$(LOCAL_PACKAGE_NAME) |
| 491 | lint-$(LOCAL_PACKAGE_NAME): PRIVATE_PATH := $(LOCAL_PATH) |
| 492 | lint-$(LOCAL_PACKAGE_NAME): PRIVATE_LINT_FLAGS := $(LOCAL_LINT_FLAGS) |
| 493 | lint-$(LOCAL_PACKAGE_NAME) : |
| 494 | @echo lint $(PRIVATE_PATH) |
| 495 | $(LINT) $(PRIVATE_LINT_FLAGS) $(PRIVATE_PATH) |
| 496 | |
| 497 | lintall : lint-$(LOCAL_PACKAGE_NAME) |
| 498 | |
| 499 | endif # skip_definition |
| 500 | |
| 501 | # Reset internal variables. |
| 502 | all_res_assets := |