Inject minSdkVersion from the build system
Add a script that can inject a <uses-sdk minSdkVersion=""> into AndroidManifest.xml files. This will help with merging LOCAL_STATIC_ANDROID_LIBRARIES, because ManifestMerger treats a missing minSdkVersion as minSdkVersion=1 and throws errors if libraries use a larger minSdkVersion. It will also help with cases where an app has a manifest that specifies an old minSdkVersion, but the build system is compiling the app in a way that is not compatibile with old devices, for example using a newer dex format. Bug: 110167203 Test: m java Change-Id: Ia60d462e8af9e93c57d75f423207fa8d221b1347
This commit is contained in:
parent
1d46e8abb4
commit
fae93680fa
1 changed files with 22 additions and 5 deletions
|
@ -6,9 +6,9 @@ ifeq ($(strip $(LOCAL_MANIFEST_FILE)),)
|
|||
LOCAL_MANIFEST_FILE := AndroidManifest.xml
|
||||
endif
|
||||
ifdef LOCAL_FULL_MANIFEST_FILE
|
||||
full_android_manifest := $(LOCAL_FULL_MANIFEST_FILE)
|
||||
main_android_manifest := $(LOCAL_FULL_MANIFEST_FILE)
|
||||
else
|
||||
full_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE)
|
||||
main_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE)
|
||||
endif
|
||||
|
||||
LOCAL_STATIC_JAVA_AAR_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_AAR_LIBRARIES))
|
||||
|
@ -32,18 +32,35 @@ ifdef LOCAL_STATIC_JAVA_AAR_LIBRARIES
|
|||
endif
|
||||
endif
|
||||
|
||||
full_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml
|
||||
|
||||
ifdef LOCAL_MIN_SDK_VERSION
|
||||
$(full_android_manifest): PRIVATE_MIN_SDK_VERSION := $(LOCAL_MIN_SDK_VERSION)
|
||||
else ifneq (,$(filter-out current system_current test_current core_current, $(LOCAL_SDK_VERSION)))
|
||||
$(full_android_manifest): PRIVATE_MIN_SDK_VERSION := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
|
||||
else
|
||||
$(full_android_manifest): PRIVATE_MIN_SDK_VERSION := $(DEFAULT_APP_TARGET_SDK)
|
||||
endif
|
||||
|
||||
# Set up rules to merge library manifest files
|
||||
ifneq (,$(strip $(my_full_libs_manifest_files)))
|
||||
|
||||
main_android_manifest := $(full_android_manifest)
|
||||
full_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml
|
||||
$(full_android_manifest): PRIVATE_LIBS_MANIFESTS := $(my_full_libs_manifest_files)
|
||||
$(full_android_manifest): $(ANDROID_MANIFEST_MERGER_CLASSPATH)
|
||||
$(full_android_manifest): $(MANIFEST_FIXER)
|
||||
$(full_android_manifest) : $(main_android_manifest) $(my_full_libs_manifest_files)
|
||||
@echo "Merge android manifest files: $@ <-- $< $(PRIVATE_LIBS_MANIFESTS)"
|
||||
@mkdir -p $(dir $@)
|
||||
$(hide) $(ANDROID_MANIFEST_MERGER) --main $< \
|
||||
$(MANIFEST_FIXER) $< $@.tmp --minSdkVersion $(PRIVATE_MIN_SDK_VERSION)
|
||||
$(hide) $(ANDROID_MANIFEST_MERGER) --main $@.tmp \
|
||||
--libs $(call normalize-path-list,$(PRIVATE_LIBS_MANIFESTS)) \
|
||||
--out $@
|
||||
rm $@.tmp
|
||||
|
||||
else
|
||||
$(full_android_manifest): $(MANIFEST_FIXER)
|
||||
$(full_android_manifest): $(main_android_manifest)
|
||||
@echo "Fix manifest: $@"
|
||||
$(MANIFEST_FIXER) $< $@ --minSdkVersion $(PRIVATE_MIN_SDK_VERSION)
|
||||
|
||||
endif
|
||||
|
|
Loading…
Reference in a new issue