This change disallows Java modules in the vendor partition to use System SDK that is newer than API level 34; 34 is the latest allowed. Background 1: with Trunk Stable, the system/vendor interface is released at Q2 whereas the system/app interface is released at Q3. In other words, at Q2, the APIs which will be added to the system SDK at Q3 are not available. Since the system/vendor interface (which is fronzen at Q2) is what the modules in the vendor partition will be building against, they can't and shouldn't use those new APIs that will be added in the future (Q3). Using those APIs is risky because there's a chance that those APIs get removed or changed between Q2 and Q3. For example, 2024 Q2 is technically still Android U, not Android V. Background 2: The use of Java APIs in the vendor partition had many issues. Most significantly, those "vendor" Java apps are categorized as part of the system partition because all Java app processes require access to platform internal libraries that are prohibited to vendor processes. Furthermore, since the Project Treble, the vendor partition was re-purposed to a partition to host SoC-dependent bits - usually HALs. Implementing HALs in Java has never been officially supported and has had many loop holes. We'd like to use both background 1 and 2 as a chance to disallow any Java code in the vendor partition. However, since there are already some Java modules in the partition, we can't suddenly ban it. The deprecation will be made gradually, and this CL is the start. This CL implements the "Make" part of the restriction. The "Soong" part will follow. Note that LOCAL_SDK_VERSION := current or LOCAL_SDK_VERSION := system_current is automatically overridden into 34 or system_34. This is to prevent sudden breakage of vendor modules that have been targetting the latest (i.e. current) API level. They will however fail if they use APIs newer than API level 34. Bug: 314011075 Test: The following Android.mk module fails as expected. some/Android.mk: include $(CLEAR_VARS) LOCAL_MODULE := example_module LOCAL_VENDOR_MODULE := true LOCAL_SDK_VERSION := system_35 LOCAL_SRC_FILES := Foo.java include $(BUILD_JAVA_LIBRARY) FAILED: some/Android.mk: error: example_module: Incompatible LOCAL_SDK_VERSION 'system_35'. System SDK version '35' is not supported. Supported versions are: 28 29 30 31 32 33 34 Change-Id: I44c29c6dc45b91a9a30b8a21cd2baae685fa27fb
91 lines
4.3 KiB
Makefile
91 lines
4.3 KiB
Makefile
#
|
|
# Copyright (C) 2018 The Android Open Source Project
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
|
|
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
|
|
# We have run below again since LOCAL_SDK_VERSION is newly set and the "_current"
|
|
# may have to be updated
|
|
include $(BUILD_SYSTEM)/local_current_sdk.mk
|
|
endif
|
|
endif
|
|
endif
|
|
endif
|
|
endif
|
|
|
|
# Ensure that the selected System SDK version is one of the supported versions.
|
|
# The range of support versions becomes narrower when BOARD_SYSTEMSDK_VERSIONS
|
|
# is set, which is a subset of PLATFORM_SYSTEMSDK_VERSIONS.
|
|
ifneq (,$(call has-system-sdk-version,$(LOCAL_SDK_VERSION)))
|
|
ifneq ($(_cannot_use_platform_apis),true)
|
|
# apps bundled in system partition can use all system sdk versions provided by the platform
|
|
_supported_systemsdk_versions := $(PLATFORM_SYSTEMSDK_VERSIONS)
|
|
else ifdef BOARD_SYSTEMSDK_VERSIONS
|
|
# When BOARD_SYSTEMSDK_VERSIONS is set, vendors apps are restricted to use those versions
|
|
# which is equal to or smaller than PLATFORM_SYSTEMSDK_VERSIONS
|
|
_supported_systemsdk_versions := $(BOARD_SYSTEMSDK_VERSIONS)
|
|
else
|
|
# If not, vendor apks are treated equally to system apps
|
|
_supported_systemsdk_versions := $(PLATFORM_SYSTEMSDK_VERSIONS)
|
|
endif
|
|
|
|
# b/314011075: apks and jars in the vendor or odm partitions cannot use system SDK 35 and beyond.
|
|
# This is to discourage the use of Java APIs in the partitions, which hasn't been supported since
|
|
# the beginning of the project Treble back in Android 10. Ultimately, we'd like to completely
|
|
# disallow any Java API in the partitions, but it shall be done progressively.
|
|
ifneq (,$(filter true,$(LOCAL_VENDOR_MODULE) $(LOCAL_ODM_MODULE) $(LOCAL_PROPRIETARY_MODULE)))
|
|
# 28 is the API level when BOARD_SYSTEMSDK_VERSIONS was introduced. So, it's the oldset API
|
|
# we allow.
|
|
_supported_systemsdk_versions := $(call int_range_list, 28, 34)
|
|
endif
|
|
|
|
# Extract version number from LOCAL_SDK_VERSION (ex: system_34 -> 34)
|
|
_system_sdk_version := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
|
|
# However, the extraction may fail if it doesn't have any number (i.e. current, core_current,
|
|
# system_current, or similar) Then use the latest platform SDK version number or the actual
|
|
# codename.
|
|
ifeq (,$(_system_sdk_version)
|
|
ifeq (REL,$(PLATFORM_VERSION_CODENAME))
|
|
_system_sdk_version := $(PLATFORM_SDK_VERSION)
|
|
else
|
|
_system_sdk_version := $(PLATFORM_VERSION_CODENAME)
|
|
endif
|
|
endif
|
|
|
|
ifneq ($(_system_sdk_version),$(filter $(_system_sdk_version),$(_supported_systemsdk_versions)))
|
|
$(call pretty-error,Incompatible LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)'. \
|
|
System SDK version '$(_system_sdk_version)' is not supported. Supported versions are: $(_supported_systemsdk_versions))
|
|
endif
|
|
_system_sdk_version :=
|
|
_supported_systemsdk_versions :=
|
|
endif
|