blob: 254e09bc9316d2ef2f11d2f557bd38f250416b7f [file] [log] [blame]
Ying Wangdc7fee92014-02-05 18:24:45 -08001# Handle AndroidManifest.xmls
Colin Crossead7b662019-02-06 16:36:32 -08002# Input: LOCAL_MANIFEST_FILE, LOCAL_FULL_MANIFEST_FILE, LOCAL_FULL_LIBS_MANIFEST_FILES,
3# LOCAL_USE_EMBEDDED_NATIVE_LIBS
Ying Wangdc7fee92014-02-05 18:24:45 -08004# Output: full_android_manifest
5
6ifeq ($(strip $(LOCAL_MANIFEST_FILE)),)
7 LOCAL_MANIFEST_FILE := AndroidManifest.xml
8endif
9ifdef LOCAL_FULL_MANIFEST_FILE
Colin Cross2d61e472018-06-18 20:18:37 +000010 main_android_manifest := $(LOCAL_FULL_MANIFEST_FILE)
Ying Wangdc7fee92014-02-05 18:24:45 -080011else
Colin Cross2d61e472018-06-18 20:18:37 +000012 main_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE)
Ying Wangdc7fee92014-02-05 18:24:45 -080013endif
14
Ying Wang12f44972015-05-27 15:14:28 -070015LOCAL_STATIC_JAVA_AAR_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_AAR_LIBRARIES))
Ying Wang2902d452014-10-29 15:48:32 -070016
Colin Cross1d46e8a2018-06-12 13:43:10 -070017my_full_libs_manifest_files :=
18
19ifndef LOCAL_DONT_MERGE_MANIFESTS
20 my_full_libs_manifest_files += $(LOCAL_FULL_LIBS_MANIFEST_FILES)
21
Colin Cross16f1dbc2018-06-07 16:44:07 -070022 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 Cross1d46e8a2018-06-12 13:43:10 -070024endif
25
Colin Cross2d61e472018-06-18 20:18:37 +000026full_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml
27
Colin Cross5c1a27f2018-06-13 12:34:51 -070028ifneq (,$(strip $(my_full_libs_manifest_files)))
Colin Crossa90b6072018-07-25 10:12:48 -070029 # Set up rules to merge library manifest files
30 fixed_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml.fixed
Colin Cross5c1a27f2018-06-13 12:34:51 -070031
Colin Crossa90b6072018-07-25 10:12:48 -070032 $(full_android_manifest): PRIVATE_LIBS_MANIFESTS := $(my_full_libs_manifest_files)
Colin Cross7293c1e2019-02-26 22:12:30 -080033 $(full_android_manifest): $(ANDROID_MANIFEST_MERGER)
Colin Crossa90b6072018-07-25 10:12:48 -070034 $(full_android_manifest) : $(fixed_android_manifest) $(my_full_libs_manifest_files)
Ying Wang2902d452014-10-29 15:48:32 -070035 @echo "Merge android manifest files: $@ <-- $< $(PRIVATE_LIBS_MANIFESTS)"
Ying Wangdc7fee92014-02-05 18:24:45 -080036 @mkdir -p $(dir $@)
Colin Crossa90b6072018-07-25 10:12:48 -070037 $(hide) $(ANDROID_MANIFEST_MERGER) --main $< \
Colin Cross710a4132017-09-08 13:29:54 -070038 --libs $(call normalize-path-list,$(PRIVATE_LIBS_MANIFESTS)) \
Ying Wangdc7fee92014-02-05 18:24:45 -080039 --out $@
Colin Cross2d61e472018-06-18 20:18:37 +000040else
Colin Crossa90b6072018-07-25 10:12:48 -070041 fixed_android_manifest := $(full_android_manifest)
Ying Wangdc7fee92014-02-05 18:24:45 -080042endif
Colin Crossa90b6072018-07-25 10:12:48 -070043
Colin Crossd60401a2019-04-18 14:46:48 -070044my_target_sdk_version := $(call module-target-sdk-version)
Baligh Uddin7ce531d2020-01-16 10:04:55 -080045my_min_sdk_version := $(call module-min-sdk-version)
Colin Crossd60401a2019-04-18 14:46:48 -070046
47ifdef TARGET_BUILD_APPS
Jeongik Chad05b57a2020-07-08 18:10:38 +090048 ifndef TARGET_BUILD_USE_PREBUILT_SDKS
Colin Crossd60401a2019-04-18 14:46:48 -070049 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 Uddin7ce531d2020-01-16 10:04:55 -080052 my_min_sdk_version := $(my_min_sdk_version).$$(cat $(API_FINGERPRINT))
Colin Crossd60401a2019-04-18 14:46:48 -070053 $(fixed_android_manifest): $(API_FINGERPRINT)
54 endif
55 endif
56 endif
57endif
58
Baligh Uddin7ce531d2020-01-16 10:04:55 -080059$(fixed_android_manifest): PRIVATE_MIN_SDK_VERSION := $(my_min_sdk_version)
Colin Crossd60401a2019-04-18 14:46:48 -070060$(fixed_android_manifest): PRIVATE_TARGET_SDK_VERSION := $(my_target_sdk_version)
Colin Cross5763fd72018-09-10 13:37:10 -070061
Colin Crossa90b6072018-07-25 10:12:48 -070062my_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 Brazdilb1082812018-08-28 12:28:38 +010066my_manifest_fixer_flags :=
Colin Crossacebb322018-07-25 16:11:31 -070067ifneq ($(LOCAL_MODULE_CLASS),APPS)
David Brazdilb1082812018-08-28 12:28:38 +010068 my_manifest_fixer_flags += --library
Colin Crossacebb322018-07-25 16:11:31 -070069endif
David Brazdilb1082812018-08-28 12:28:38 +010070ifeq ($(LOCAL_PRIVATE_PLATFORM_APIS),true)
71 my_manifest_fixer_flags += --uses-non-sdk-api
72endif
Victor Hsiehe53dd7b2018-10-22 11:25:05 -070073
Victor Hsieh06769c72019-01-29 13:03:22 -080074ifeq (true,$(LOCAL_USE_EMBEDDED_DEX))
75 my_manifest_fixer_flags += --use-embedded-dex
Victor Hsiehe53dd7b2018-10-22 11:25:05 -070076endif
77
Colin Crossead7b662019-02-06 16:36:32 -080078ifeq ($(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
88endif
89
David Brazdilb1082812018-08-28 12:28:38 +010090$(fixed_android_manifest): PRIVATE_MANIFEST_FIXER_FLAGS := $(my_manifest_fixer_flags)
Jiyong Park4a602952018-10-16 10:59:55 +090091# 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 Crossa90b6072018-07-25 10:12:48 -070097$(fixed_android_manifest): $(MANIFEST_FIXER)
98$(fixed_android_manifest): $(main_android_manifest)
Jiyong Park4a602952018-10-16 10:59:55 +090099 echo $(PRIVATE_OPTIONAL_SDK_LIB_NAMES) | tr ' ' '\n' > $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional
Colin Crossa90b6072018-07-25 10:12:48 -0700100 @echo "Fix manifest: $@"
101 $(MANIFEST_FIXER) \
102 --minSdkVersion $(PRIVATE_MIN_SDK_VERSION) \
Colin Cross5763fd72018-09-10 13:37:10 -0700103 --targetSdkVersion $(PRIVATE_TARGET_SDK_VERSION) \
104 --raise-min-sdk-version \
Colin Crossacebb322018-07-25 16:11:31 -0700105 $(PRIVATE_MANIFEST_FIXER_FLAGS) \
Colin Crossa90b6072018-07-25 10:12:48 -0700106 $(if (PRIVATE_EXPORTED_SDK_LIBS_FILE),\
Jiyong Park4a602952018-10-16 10:59:55 +0900107 $$(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 Crossa90b6072018-07-25 10:12:48 -0700110 $< $@
Jiyong Park4a602952018-10-16 10:59:55 +0900111 rm $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional