Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 1 | # Handle AndroidManifest.xmls |
Colin Cross | ead7b66 | 2019-02-06 16:36:32 -0800 | [diff] [blame] | 2 | # Input: LOCAL_MANIFEST_FILE, LOCAL_FULL_MANIFEST_FILE, LOCAL_FULL_LIBS_MANIFEST_FILES, |
| 3 | # LOCAL_USE_EMBEDDED_NATIVE_LIBS |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 4 | # Output: full_android_manifest |
| 5 | |
| 6 | ifeq ($(strip $(LOCAL_MANIFEST_FILE)),) |
| 7 | LOCAL_MANIFEST_FILE := AndroidManifest.xml |
| 8 | endif |
| 9 | ifdef LOCAL_FULL_MANIFEST_FILE |
Colin Cross | 2d61e47 | 2018-06-18 20:18:37 +0000 | [diff] [blame] | 10 | main_android_manifest := $(LOCAL_FULL_MANIFEST_FILE) |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 11 | else |
Colin Cross | 2d61e47 | 2018-06-18 20:18:37 +0000 | [diff] [blame] | 12 | main_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE) |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 13 | endif |
| 14 | |
Ying Wang | 12f4497 | 2015-05-27 15:14:28 -0700 | [diff] [blame] | 15 | LOCAL_STATIC_JAVA_AAR_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)) |
Ying Wang | 2902d45 | 2014-10-29 15:48:32 -0700 | [diff] [blame] | 16 | |
Colin Cross | 1d46e8a | 2018-06-12 13:43:10 -0700 | [diff] [blame] | 17 | my_full_libs_manifest_files := |
| 18 | |
| 19 | ifndef LOCAL_DONT_MERGE_MANIFESTS |
| 20 | my_full_libs_manifest_files += $(LOCAL_FULL_LIBS_MANIFEST_FILES) |
| 21 | |
Colin Cross | 16f1dbc | 2018-06-07 16:44:07 -0700 | [diff] [blame] | 22 | my_full_libs_manifest_files += $(foreach lib, $(LOCAL_STATIC_JAVA_AAR_LIBRARIES) $(LOCAL_STATIC_ANDROID_LIBRARIES),\ |
| 23 | $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/manifest/AndroidManifest.xml) |
Colin Cross | 1d46e8a | 2018-06-12 13:43:10 -0700 | [diff] [blame] | 24 | endif |
| 25 | |
Colin Cross | 2d61e47 | 2018-06-18 20:18:37 +0000 | [diff] [blame] | 26 | full_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml |
| 27 | |
Colin Cross | 5c1a27f | 2018-06-13 12:34:51 -0700 | [diff] [blame] | 28 | ifneq (,$(strip $(my_full_libs_manifest_files))) |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 29 | # Set up rules to merge library manifest files |
| 30 | fixed_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml.fixed |
Colin Cross | 5c1a27f | 2018-06-13 12:34:51 -0700 | [diff] [blame] | 31 | |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 32 | $(full_android_manifest): PRIVATE_LIBS_MANIFESTS := $(my_full_libs_manifest_files) |
Colin Cross | 7293c1e | 2019-02-26 22:12:30 -0800 | [diff] [blame] | 33 | $(full_android_manifest): $(ANDROID_MANIFEST_MERGER) |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 34 | $(full_android_manifest) : $(fixed_android_manifest) $(my_full_libs_manifest_files) |
Ying Wang | 2902d45 | 2014-10-29 15:48:32 -0700 | [diff] [blame] | 35 | @echo "Merge android manifest files: $@ <-- $< $(PRIVATE_LIBS_MANIFESTS)" |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 36 | @mkdir -p $(dir $@) |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 37 | $(hide) $(ANDROID_MANIFEST_MERGER) --main $< \ |
Colin Cross | 710a413 | 2017-09-08 13:29:54 -0700 | [diff] [blame] | 38 | --libs $(call normalize-path-list,$(PRIVATE_LIBS_MANIFESTS)) \ |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 39 | --out $@ |
Colin Cross | 2d61e47 | 2018-06-18 20:18:37 +0000 | [diff] [blame] | 40 | else |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 41 | fixed_android_manifest := $(full_android_manifest) |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 42 | endif |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 43 | |
Colin Cross | d60401a | 2019-04-18 14:46:48 -0700 | [diff] [blame] | 44 | my_target_sdk_version := $(call module-target-sdk-version) |
Baligh Uddin | 7ce531d | 2020-01-16 10:04:55 -0800 | [diff] [blame] | 45 | my_min_sdk_version := $(call module-min-sdk-version) |
Colin Cross | d60401a | 2019-04-18 14:46:48 -0700 | [diff] [blame] | 46 | |
| 47 | ifdef TARGET_BUILD_APPS |
Jeongik Cha | d05b57a | 2020-07-08 18:10:38 +0900 | [diff] [blame] | 48 | ifndef TARGET_BUILD_USE_PREBUILT_SDKS |
Colin Cross | d60401a | 2019-04-18 14:46:48 -0700 | [diff] [blame] | 49 | ifeq ($(my_target_sdk_version),$(PLATFORM_VERSION_CODENAME)) |
| 50 | ifdef UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT |
| 51 | my_target_sdk_version := $(my_target_sdk_version).$$(cat $(API_FINGERPRINT)) |
Baligh Uddin | 7ce531d | 2020-01-16 10:04:55 -0800 | [diff] [blame] | 52 | my_min_sdk_version := $(my_min_sdk_version).$$(cat $(API_FINGERPRINT)) |
Colin Cross | d60401a | 2019-04-18 14:46:48 -0700 | [diff] [blame] | 53 | $(fixed_android_manifest): $(API_FINGERPRINT) |
| 54 | endif |
| 55 | endif |
| 56 | endif |
| 57 | endif |
| 58 | |
Baligh Uddin | 7ce531d | 2020-01-16 10:04:55 -0800 | [diff] [blame] | 59 | $(fixed_android_manifest): PRIVATE_MIN_SDK_VERSION := $(my_min_sdk_version) |
Colin Cross | d60401a | 2019-04-18 14:46:48 -0700 | [diff] [blame] | 60 | $(fixed_android_manifest): PRIVATE_TARGET_SDK_VERSION := $(my_target_sdk_version) |
Colin Cross | 5763fd7 | 2018-09-10 13:37:10 -0700 | [diff] [blame] | 61 | |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 62 | my_exported_sdk_libs_file := $(call local-intermediates-dir,COMMON)/exported-sdk-libs |
| 63 | $(fixed_android_manifest): PRIVATE_EXPORTED_SDK_LIBS_FILE := $(my_exported_sdk_libs_file) |
| 64 | $(fixed_android_manifest): $(my_exported_sdk_libs_file) |
| 65 | |
David Brazdil | b108281 | 2018-08-28 12:28:38 +0100 | [diff] [blame] | 66 | my_manifest_fixer_flags := |
Colin Cross | acebb32 | 2018-07-25 16:11:31 -0700 | [diff] [blame] | 67 | ifneq ($(LOCAL_MODULE_CLASS),APPS) |
David Brazdil | b108281 | 2018-08-28 12:28:38 +0100 | [diff] [blame] | 68 | my_manifest_fixer_flags += --library |
Colin Cross | acebb32 | 2018-07-25 16:11:31 -0700 | [diff] [blame] | 69 | endif |
David Brazdil | b108281 | 2018-08-28 12:28:38 +0100 | [diff] [blame] | 70 | ifeq ($(LOCAL_PRIVATE_PLATFORM_APIS),true) |
| 71 | my_manifest_fixer_flags += --uses-non-sdk-api |
| 72 | endif |
Victor Hsieh | e53dd7b | 2018-10-22 11:25:05 -0700 | [diff] [blame] | 73 | |
Victor Hsieh | 06769c7 | 2019-01-29 13:03:22 -0800 | [diff] [blame] | 74 | ifeq (true,$(LOCAL_USE_EMBEDDED_DEX)) |
| 75 | my_manifest_fixer_flags += --use-embedded-dex |
Victor Hsieh | e53dd7b | 2018-10-22 11:25:05 -0700 | [diff] [blame] | 76 | endif |
| 77 | |
Colin Cross | ead7b66 | 2019-02-06 16:36:32 -0800 | [diff] [blame] | 78 | ifeq ($(LOCAL_MODULE_CLASS),APPS) |
| 79 | ifeq (true,$(call math_gt_or_eq,$(patsubst $(PLATFORM_VERSION_CODENAME),100,$(call module-min-sdk-version)),23)) |
| 80 | ifeq (true,$(LOCAL_USE_EMBEDDED_NATIVE_LIBS)) |
| 81 | my_manifest_fixer_flags += --extract-native-libs=false |
| 82 | else |
| 83 | my_manifest_fixer_flags += --extract-native-libs=true |
| 84 | endif |
| 85 | else ifeq (true,$(LOCAL_USE_EMBEDDED_NATIVE_LIBS)) |
| 86 | $(call pretty-error,LOCAL_USE_EMBEDDED_NATIVE_LIBS is set but minSdkVersion $(call module-min-sdk-version) does not support it) |
| 87 | endif |
| 88 | endif |
| 89 | |
David Brazdil | b108281 | 2018-08-28 12:28:38 +0100 | [diff] [blame] | 90 | $(fixed_android_manifest): PRIVATE_MANIFEST_FIXER_FLAGS := $(my_manifest_fixer_flags) |
Jiyong Park | 4a60295 | 2018-10-16 10:59:55 +0900 | [diff] [blame] | 91 | # These two libs are added as optional dependencies (<uses-library> with |
| 92 | # android:required set to false). This is because they haven't existed in pre-P |
| 93 | # devices, but classes in them were in bootclasspath jars, etc. So making them |
| 94 | # hard dependencies (andriod:required=true) would prevent apps from being |
| 95 | # installed to such legacy devices. |
| 96 | $(fixed_android_manifest): PRIVATE_OPTIONAL_SDK_LIB_NAMES := android.test.base android.test.mock |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 97 | $(fixed_android_manifest): $(MANIFEST_FIXER) |
| 98 | $(fixed_android_manifest): $(main_android_manifest) |
Jiyong Park | 4a60295 | 2018-10-16 10:59:55 +0900 | [diff] [blame] | 99 | echo $(PRIVATE_OPTIONAL_SDK_LIB_NAMES) | tr ' ' '\n' > $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 100 | @echo "Fix manifest: $@" |
| 101 | $(MANIFEST_FIXER) \ |
| 102 | --minSdkVersion $(PRIVATE_MIN_SDK_VERSION) \ |
Colin Cross | 5763fd7 | 2018-09-10 13:37:10 -0700 | [diff] [blame] | 103 | --targetSdkVersion $(PRIVATE_TARGET_SDK_VERSION) \ |
| 104 | --raise-min-sdk-version \ |
Colin Cross | acebb32 | 2018-07-25 16:11:31 -0700 | [diff] [blame] | 105 | $(PRIVATE_MANIFEST_FIXER_FLAGS) \ |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 106 | $(if (PRIVATE_EXPORTED_SDK_LIBS_FILE),\ |
Jiyong Park | 4a60295 | 2018-10-16 10:59:55 +0900 | [diff] [blame] | 107 | $$(cat $(PRIVATE_EXPORTED_SDK_LIBS_FILE) | grep -v -f $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional | sort -u | sed -e 's/^/\ --uses-library\ /' | tr '\n' ' ') \ |
| 108 | $$(cat $(PRIVATE_EXPORTED_SDK_LIBS_FILE) | grep -f $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional | sort -u | sed -e 's/^/\ --optional-uses-library\ /' | tr '\n' ' ') \ |
| 109 | ) \ |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 110 | $< $@ |
Jiyong Park | 4a60295 | 2018-10-16 10:59:55 +0900 | [diff] [blame] | 111 | rm $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional |