Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 1 | # Handle AndroidManifest.xmls |
| 2 | # Input: LOCAL_MANIFEST_FILE, LOCAL_FULL_MANIFEST_FILE, LOCAL_FULL_LIBS_MANIFEST_FILES |
| 3 | # Output: full_android_manifest |
| 4 | |
| 5 | ifeq ($(strip $(LOCAL_MANIFEST_FILE)),) |
| 6 | LOCAL_MANIFEST_FILE := AndroidManifest.xml |
| 7 | endif |
| 8 | ifdef LOCAL_FULL_MANIFEST_FILE |
Colin Cross | 2d61e47 | 2018-06-18 20:18:37 +0000 | [diff] [blame] | 9 | main_android_manifest := $(LOCAL_FULL_MANIFEST_FILE) |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 10 | else |
Colin Cross | 2d61e47 | 2018-06-18 20:18:37 +0000 | [diff] [blame] | 11 | main_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE) |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 12 | endif |
| 13 | |
Ying Wang | 12f4497 | 2015-05-27 15:14:28 -0700 | [diff] [blame] | 14 | LOCAL_STATIC_JAVA_AAR_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)) |
Ying Wang | 2902d45 | 2014-10-29 15:48:32 -0700 | [diff] [blame] | 15 | |
Colin Cross | 1d46e8a | 2018-06-12 13:43:10 -0700 | [diff] [blame] | 16 | my_full_libs_manifest_files := |
| 17 | |
| 18 | ifndef LOCAL_DONT_MERGE_MANIFESTS |
| 19 | my_full_libs_manifest_files += $(LOCAL_FULL_LIBS_MANIFEST_FILES) |
| 20 | |
Colin Cross | 16f1dbc | 2018-06-07 16:44:07 -0700 | [diff] [blame] | 21 | my_full_libs_manifest_files += $(foreach lib, $(LOCAL_STATIC_JAVA_AAR_LIBRARIES) $(LOCAL_STATIC_ANDROID_LIBRARIES),\ |
| 22 | $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/manifest/AndroidManifest.xml) |
Colin Cross | 1d46e8a | 2018-06-12 13:43:10 -0700 | [diff] [blame] | 23 | endif |
| 24 | |
Colin Cross | 16f1dbc | 2018-06-07 16:44:07 -0700 | [diff] [blame] | 25 | # With aapt2, we'll link in the built resource from the AAR. |
| 26 | ifneq ($(LOCAL_USE_AAPT2),true) |
| 27 | LOCAL_RESOURCE_DIR += $(foreach lib, $(LOCAL_STATIC_JAVA_AAR_LIBRARIES),\ |
| 28 | $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/aar/res) |
Colin Cross | 1d46e8a | 2018-06-12 13:43:10 -0700 | [diff] [blame] | 29 | endif |
Ying Wang | 2902d45 | 2014-10-29 15:48:32 -0700 | [diff] [blame] | 30 | |
Colin Cross | 2d61e47 | 2018-06-18 20:18:37 +0000 | [diff] [blame] | 31 | full_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml |
| 32 | |
Colin Cross | 5c1a27f | 2018-06-13 12:34:51 -0700 | [diff] [blame] | 33 | ifneq (,$(strip $(my_full_libs_manifest_files))) |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 34 | # Set up rules to merge library manifest files |
| 35 | fixed_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml.fixed |
Colin Cross | 5c1a27f | 2018-06-13 12:34:51 -0700 | [diff] [blame] | 36 | |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 37 | $(full_android_manifest): PRIVATE_LIBS_MANIFESTS := $(my_full_libs_manifest_files) |
| 38 | $(full_android_manifest): $(ANDROID_MANIFEST_MERGER_DEPS) |
| 39 | $(full_android_manifest) : $(fixed_android_manifest) $(my_full_libs_manifest_files) |
Ying Wang | 2902d45 | 2014-10-29 15:48:32 -0700 | [diff] [blame] | 40 | @echo "Merge android manifest files: $@ <-- $< $(PRIVATE_LIBS_MANIFESTS)" |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 41 | @mkdir -p $(dir $@) |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 42 | $(hide) $(ANDROID_MANIFEST_MERGER) --main $< \ |
Colin Cross | 710a413 | 2017-09-08 13:29:54 -0700 | [diff] [blame] | 43 | --libs $(call normalize-path-list,$(PRIVATE_LIBS_MANIFESTS)) \ |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 44 | --out $@ |
Colin Cross | 2d61e47 | 2018-06-18 20:18:37 +0000 | [diff] [blame] | 45 | else |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 46 | fixed_android_manifest := $(full_android_manifest) |
Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 47 | endif |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 48 | |
Colin Cross | fedcf86 | 2018-09-10 13:47:48 -0700 | [diff] [blame] | 49 | ifdef LOCAL_MIN_SDK_VERSION |
| 50 | $(fixed_android_manifest): PRIVATE_MIN_SDK_VERSION := $(LOCAL_MIN_SDK_VERSION) |
| 51 | else ifneq (,$(filter-out current system_current test_current core_current, $(LOCAL_SDK_VERSION))) |
| 52 | $(fixed_android_manifest): PRIVATE_MIN_SDK_VERSION := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION)) |
| 53 | else |
| 54 | $(fixed_android_manifest): PRIVATE_MIN_SDK_VERSION := $(DEFAULT_APP_TARGET_SDK) |
| 55 | endif |
| 56 | |
Colin Cross | 5763fd7 | 2018-09-10 13:37:10 -0700 | [diff] [blame] | 57 | ifneq (,$(filter-out current system_current test_current core_current, $(LOCAL_SDK_VERSION))) |
| 58 | $(fixed_android_manifest): PRIVATE_TARGET_SDK_VERSION := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION)) |
| 59 | else |
| 60 | $(fixed_android_manifest): PRIVATE_TARGET_SDK_VERSION := $(DEFAULT_APP_TARGET_SDK) |
| 61 | endif |
| 62 | |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 63 | my_exported_sdk_libs_file := $(call local-intermediates-dir,COMMON)/exported-sdk-libs |
| 64 | $(fixed_android_manifest): PRIVATE_EXPORTED_SDK_LIBS_FILE := $(my_exported_sdk_libs_file) |
| 65 | $(fixed_android_manifest): $(my_exported_sdk_libs_file) |
| 66 | |
David Brazdil | b108281 | 2018-08-28 12:28:38 +0100 | [diff] [blame] | 67 | my_manifest_fixer_flags := |
Colin Cross | acebb32 | 2018-07-25 16:11:31 -0700 | [diff] [blame] | 68 | ifneq ($(LOCAL_MODULE_CLASS),APPS) |
David Brazdil | b108281 | 2018-08-28 12:28:38 +0100 | [diff] [blame] | 69 | my_manifest_fixer_flags += --library |
Colin Cross | acebb32 | 2018-07-25 16:11:31 -0700 | [diff] [blame] | 70 | endif |
David Brazdil | b108281 | 2018-08-28 12:28:38 +0100 | [diff] [blame] | 71 | ifeq ($(LOCAL_PRIVATE_PLATFORM_APIS),true) |
| 72 | my_manifest_fixer_flags += --uses-non-sdk-api |
| 73 | endif |
| 74 | $(fixed_android_manifest): PRIVATE_MANIFEST_FIXER_FLAGS := $(my_manifest_fixer_flags) |
Jiyong Park | 4a60295 | 2018-10-16 10:59:55 +0900 | [diff] [blame^] | 75 | # These two libs are added as optional dependencies (<uses-library> with |
| 76 | # android:required set to false). This is because they haven't existed in pre-P |
| 77 | # devices, but classes in them were in bootclasspath jars, etc. So making them |
| 78 | # hard dependencies (andriod:required=true) would prevent apps from being |
| 79 | # installed to such legacy devices. |
| 80 | $(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] | 81 | $(fixed_android_manifest): $(MANIFEST_FIXER) |
| 82 | $(fixed_android_manifest): $(main_android_manifest) |
Jiyong Park | 4a60295 | 2018-10-16 10:59:55 +0900 | [diff] [blame^] | 83 | 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] | 84 | @echo "Fix manifest: $@" |
| 85 | $(MANIFEST_FIXER) \ |
| 86 | --minSdkVersion $(PRIVATE_MIN_SDK_VERSION) \ |
Colin Cross | 5763fd7 | 2018-09-10 13:37:10 -0700 | [diff] [blame] | 87 | --targetSdkVersion $(PRIVATE_TARGET_SDK_VERSION) \ |
| 88 | --raise-min-sdk-version \ |
Colin Cross | acebb32 | 2018-07-25 16:11:31 -0700 | [diff] [blame] | 89 | $(PRIVATE_MANIFEST_FIXER_FLAGS) \ |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 90 | $(if (PRIVATE_EXPORTED_SDK_LIBS_FILE),\ |
Jiyong Park | 4a60295 | 2018-10-16 10:59:55 +0900 | [diff] [blame^] | 91 | $$(cat $(PRIVATE_EXPORTED_SDK_LIBS_FILE) | grep -v -f $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional | sort -u | sed -e 's/^/\ --uses-library\ /' | tr '\n' ' ') \ |
| 92 | $$(cat $(PRIVATE_EXPORTED_SDK_LIBS_FILE) | grep -f $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional | sort -u | sed -e 's/^/\ --optional-uses-library\ /' | tr '\n' ' ') \ |
| 93 | ) \ |
Colin Cross | a90b607 | 2018-07-25 10:12:48 -0700 | [diff] [blame] | 94 | $< $@ |
Jiyong Park | 4a60295 | 2018-10-16 10:59:55 +0900 | [diff] [blame^] | 95 | rm $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional |