blob: 931b1b18719ee57d4a32cc29fddaae35f89c116a [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 Cross16f1dbc2018-06-07 16:44:07 -070026# With aapt2, we'll link in the built resource from the AAR.
27ifneq ($(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 Cross1d46e8a2018-06-12 13:43:10 -070030endif
Ying Wang2902d452014-10-29 15:48:32 -070031
Colin Cross2d61e472018-06-18 20:18:37 +000032full_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml
33
Colin Cross5c1a27f2018-06-13 12:34:51 -070034ifneq (,$(strip $(my_full_libs_manifest_files)))
Colin Crossa90b6072018-07-25 10:12:48 -070035 # Set up rules to merge library manifest files
36 fixed_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml.fixed
Colin Cross5c1a27f2018-06-13 12:34:51 -070037
Colin Crossa90b6072018-07-25 10:12:48 -070038 $(full_android_manifest): PRIVATE_LIBS_MANIFESTS := $(my_full_libs_manifest_files)
Colin Cross7293c1e2019-02-26 22:12:30 -080039 $(full_android_manifest): $(ANDROID_MANIFEST_MERGER)
Colin Crossa90b6072018-07-25 10:12:48 -070040 $(full_android_manifest) : $(fixed_android_manifest) $(my_full_libs_manifest_files)
Ying Wang2902d452014-10-29 15:48:32 -070041 @echo "Merge android manifest files: $@ <-- $< $(PRIVATE_LIBS_MANIFESTS)"
Ying Wangdc7fee92014-02-05 18:24:45 -080042 @mkdir -p $(dir $@)
Colin Crossa90b6072018-07-25 10:12:48 -070043 $(hide) $(ANDROID_MANIFEST_MERGER) --main $< \
Colin Cross710a4132017-09-08 13:29:54 -070044 --libs $(call normalize-path-list,$(PRIVATE_LIBS_MANIFESTS)) \
Ying Wangdc7fee92014-02-05 18:24:45 -080045 --out $@
Colin Cross2d61e472018-06-18 20:18:37 +000046else
Colin Crossa90b6072018-07-25 10:12:48 -070047 fixed_android_manifest := $(full_android_manifest)
Ying Wangdc7fee92014-02-05 18:24:45 -080048endif
Colin Crossa90b6072018-07-25 10:12:48 -070049
Colin Crossa27f42a2019-02-06 15:40:03 -080050$(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 Cross5763fd72018-09-10 13:37:10 -070052
Colin Crossa90b6072018-07-25 10:12:48 -070053my_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 Brazdilb1082812018-08-28 12:28:38 +010057my_manifest_fixer_flags :=
Colin Crossacebb322018-07-25 16:11:31 -070058ifneq ($(LOCAL_MODULE_CLASS),APPS)
David Brazdilb1082812018-08-28 12:28:38 +010059 my_manifest_fixer_flags += --library
Colin Crossacebb322018-07-25 16:11:31 -070060endif
David Brazdilb1082812018-08-28 12:28:38 +010061ifeq ($(LOCAL_PRIVATE_PLATFORM_APIS),true)
62 my_manifest_fixer_flags += --uses-non-sdk-api
63endif
Victor Hsiehe53dd7b2018-10-22 11:25:05 -070064
Victor Hsieh06769c72019-01-29 13:03:22 -080065ifeq (true,$(LOCAL_USE_EMBEDDED_DEX))
66 my_manifest_fixer_flags += --use-embedded-dex
Victor Hsiehe53dd7b2018-10-22 11:25:05 -070067endif
68
Colin Crossead7b662019-02-06 16:36:32 -080069ifeq ($(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
79endif
80
David Brazdilb1082812018-08-28 12:28:38 +010081$(fixed_android_manifest): PRIVATE_MANIFEST_FIXER_FLAGS := $(my_manifest_fixer_flags)
Jiyong Park4a602952018-10-16 10:59:55 +090082# 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 Crossa90b6072018-07-25 10:12:48 -070088$(fixed_android_manifest): $(MANIFEST_FIXER)
89$(fixed_android_manifest): $(main_android_manifest)
Jiyong Park4a602952018-10-16 10:59:55 +090090 echo $(PRIVATE_OPTIONAL_SDK_LIB_NAMES) | tr ' ' '\n' > $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional
Colin Crossa90b6072018-07-25 10:12:48 -070091 @echo "Fix manifest: $@"
92 $(MANIFEST_FIXER) \
93 --minSdkVersion $(PRIVATE_MIN_SDK_VERSION) \
Colin Cross5763fd72018-09-10 13:37:10 -070094 --targetSdkVersion $(PRIVATE_TARGET_SDK_VERSION) \
95 --raise-min-sdk-version \
Colin Crossacebb322018-07-25 16:11:31 -070096 $(PRIVATE_MANIFEST_FIXER_FLAGS) \
Colin Crossa90b6072018-07-25 10:12:48 -070097 $(if (PRIVATE_EXPORTED_SDK_LIBS_FILE),\
Jiyong Park4a602952018-10-16 10:59:55 +090098 $$(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 Crossa90b6072018-07-25 10:12:48 -0700101 $< $@
Jiyong Park4a602952018-10-16 10:59:55 +0900102 rm $(PRIVATE_EXPORTED_SDK_LIBS_FILE).optional