Set min SDK for android prebuilts
Bug: 30966099
Change-Id: Iaff634d4fc1938f1b8e44c5c24f85a5e82a3442b
diff --git a/Android.mk b/Android.mk
index ce45497..745dc6d 100644
--- a/Android.mk
+++ b/Android.mk
@@ -16,13 +16,37 @@
LOCAL_PATH:= $(call my-dir)
+# $(1): tested value
+define is_number
+$(shell if [[ $(1) =~ ^[0-9]+$$ ]] ; then echo true ; fi)
+endef
+
+# $(1): sdk version
+define declare_sdk_prebuilts
+
include $(CLEAR_VARS)
+LOCAL_MODULE := sdk_v$(1)
+LOCAL_SRC_FILES := $(1)/android.jar
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
+LOCAL_BUILT_MODULE_STEM := sdk_v$(1)$(COMMON_JAVA_PACKAGE_SUFFIX)
+LOCAL_MIN_SDK_VERSION := $(if $(call is_number,$(strip $(1))),$(1),$(PLATFORM_JACK_MIN_SDK_VERSION))
+LOCAL_UNINSTALLABLE_MODULE := true
+include $(BUILD_PREBUILT)
-LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
- $(foreach s,$(TARGET_AVAILABLE_SDK_VERSIONS),\
- sdk_v$(s):$(s)/android.jar \
- uiautomator_sdk_v$(s):$(s)/uiautomator.jar)
+include $(CLEAR_VARS)
+LOCAL_MODULE := uiautomator_sdk_v$(1)
+LOCAL_SRC_FILES := $(1)/uiautomator.jar
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
+LOCAL_BUILT_MODULE_STEM := uiautomator_sdk_v$(1)$(COMMON_JAVA_PACKAGE_SUFFIX)
+LOCAL_MIN_SDK_VERSION := $(if $(call is_number,$(strip $(1))),$(1),$(PLATFORM_JACK_MIN_SDK_VERSION))
+LOCAL_UNINSTALLABLE_MODULE := true
+include $(BUILD_PREBUILT)
-include $(BUILD_MULTI_PREBUILT)
+endef
+
+$(foreach s,$(TARGET_AVAILABLE_SDK_VERSIONS),\
+ $(eval $(call declare_sdk_prebuilts,$(s))))
include $(call all-makefiles-under,$(LOCAL_PATH))