I am an Android Firmware developer, working with a source of Android 12. I am facing an issue while I try to build a system application called ServiceMode. I am trying to build this application along with Android build and move it to system partition.
I get the below build error in Android.mk definition written by me: "Specifies both LOCAL_SDK_VERSION (system_current) and LOCAL_PRIVATE_PLATFORM_APIS (true) but should specify only one"
In my makefile I have mentioned only LOCAL_PRIVATE_PLATFORM_APIS := true, since I am using hidden APIs and I haven't mentioned LOCAL_SDK_VERSION. But still I am getting a build error stating that both LOCAL_SDK_VERSION and LOCAL_PRIVATE_PLATFORM_APIS are mentioned in Android.mk
My Android.mk file looks like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES += $(call all-java-files-under, java/com/foo/example/servicemode)
LOCAL_SRC_FILES += $(call all-java-files-under, java/com/bar)
ifeq "$(LOCAL_REGION)" "JP"
LOCAL_MANIFEST_FILE := java/com/foo/example/servicemodejp/AndroidManifest.xml
LOCAL_SRC_FILES += $(call all-java-files-under, java/com/foo/example/servicemodejp)
endif
ifeq "$(PROJECT_SERIES)_$(LOCAL_REGION)" "US"
LOCAL_MANIFEST_FILE := java/com/foo/example/servicemodeus/AndroidManifest.xml
LOCAL_SRC_FILES += $(call all-java-files-under, java/com/foo/example/servicemodeus)
endif
LOCAL_PACKAGE_NAME := ServiceMode
LOCAL_CERTIFICATE := platform
LOCAL_ODM_MODULE := true
LOCAL_JAVA_LIBRARIES := com.bar.twoworlds.mobile\
com.foo.example.mobileinput.provider.util \
ifeq "$(LOCAL_REGION)" "JP"
LOCAL_JAVA_LIBRARIES += com.foo.example.jp
endif
LOCAL_STATIC_JAVA_LIBRARIES := \
com.foo.example.osdplanevisibilitymanager \
com.foo.example.provider.modelvariation.util \
com.foo.example.hardware.display-V1.0-java\
android-support-annotations
ifeq "$(PROJECT_SERIES)_$(LOCAL_REGION)" "US"
LOCAL_STATIC_JAVA_LIBRARIES += com.foo.example.mobileapi
endif
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_DEX_PREOPT := false
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
com.foo.example.osdplanevisibilitymanager:libs/com.foo.example.osdplanevisibilitymanager.jar
ifeq "$(PROJECT_SERIES)_$(LOCAL_REGION)" "US"
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += com.foo.example.mobileapi:libs/mobileapi-1.13.0.jar
endif
include $(BUILD_MULTI_PREBUILT)
Apps in vendor/odm/product partitions are not allowd to use private api.
ifdef BOARD_SYSTEMSDK_VERSIONS
# Apps and jars in vendor, product or odm partition are forced to build against System SDK.
_cannot_use_platform_apis :=
ifneq (,$(filter true,$(LOCAL_VENDOR_MODULE) $(LOCAL_ODM_MODULE) $(LOCAL_PROPRIETARY_MODULE)))
# Note: no need to check LOCAL_MODULE_PATH* since LOCAL_[VENDOR|ODM|OEM]_MODULE is already
# set correctly before this is included.
_cannot_use_platform_apis := true
else ifeq ($(LOCAL_PRODUCT_MODULE),true)
ifeq ($(PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE),true)
_cannot_use_platform_apis := true
endif
endif
ifneq (,$(filter JAVA_LIBRARIES APPS,$(LOCAL_MODULE_CLASS)))
ifndef LOCAL_SDK_VERSION
ifeq ($(_cannot_use_platform_apis),true)
ifeq (,$(LOCAL_IS_RUNTIME_RESOURCE_OVERLAY))
# Runtime resource overlays are exempted from building against System SDK.
# TODO(b/155027019): remove this, after no product/vendor apps rely on this behavior.
LOCAL_SDK_VERSION := system_current
endif
endif
endif
endif
endif
The rule is enforced to make sure that the system img(Android Framework) can be upgraded while the other img are not upgraded.
You have set LOCAL_ODM_MODULE to true, which will caused that LOCAL_SDK_VERSION are set as system_current. Then the error message will be shown.