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