TargetSDKVersion

TargetSDKVersion

#Overview

name: TargetSDKVersion

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 5 C++ source files. Also referenced in 2 C# build files meaning it may affect the build system logic.

#Summary

#Usage in the C++ source code

The purpose of TargetSDKVersion is to specify the target Android SDK version for the application being developed using Unreal Engine 5. This setting is crucial for Android app development as it determines the API level the app is designed to run on.

This setting variable is primarily used by the Android-specific subsystems of Unreal Engine, particularly the Android Runtime Settings module and the Android Platform Misc functionality within the Core module.

The value of this variable is set in the Android Runtime Settings, which can be configured through the Unreal Engine editor. It’s defined as an UPROPERTY in the UAndroidRuntimeSettings class, allowing it to be edited in the project settings.

TargetSDKVersion interacts with other Android-specific variables such as AndroidVersion, AndroidMajorVersion, and various device information variables (DeviceMake, DeviceModel, etc.). These variables collectively provide a comprehensive view of the Android environment the app is running on.

Developers must be aware that:

  1. The TargetSDKVersion should not be set lower than 26, as indicated in the comment.
  2. This variable directly impacts the app’s compatibility with different Android versions and the features it can use.
  3. Changing this value may require adjustments to the app’s code to ensure compatibility with the target SDK version.

Best practices when using this variable include:

  1. Keep it updated to target recent Android SDK versions for better performance and access to new features.
  2. Ensure that the app’s functionality is thoroughly tested on devices running the target SDK version and below.
  3. Be aware of API changes between SDK versions and adjust the app’s code accordingly.
  4. Consider the balance between targeting a higher SDK version for new features and maintaining compatibility with a wider range of devices.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:3061, section: [/Script/AndroidRuntimeSettings.AndroidRuntimeSettings]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Android/AndroidRuntimeSettings/Classes/AndroidRuntimeSettings.h:224

Scope (from outer to inner):

file
class        class UAndroidRuntimeSettings : public UObject

Source code excerpt:

	// What OS version the app is expected to run on (do not set this lower than 26)
	UPROPERTY(GlobalConfig, EditAnywhere, Category = "APK Packaging", Meta = (DisplayName = "Target SDK Version (26=8.0.0, 27=8.1.0, 28=9, 29=10, 30=11, 31=12)"))
	int32 TargetSDKVersion;

	// Preferred install location for the application
	UPROPERTY(GlobalConfig, EditAnywhere, Category = "APK Packaging")
	TEnumAsByte<EAndroidInstallLocation::Type> InstallLocation;

	// Enable -Xlint:unchecked and -Xlint:depreciation for Java compiling (Gradle only)

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Android/AndroidPlatformMisc.cpp:118

Scope: file

Source code excerpt:

FString FAndroidMisc::AndroidVersion; // version of android we are running eg "4.0.4"
int32 FAndroidMisc::AndroidMajorVersion = 0; // integer major version of Android we are running, eg 10
int32 FAndroidMisc::TargetSDKVersion = 0; // Target SDK version, eg 29.
FString FAndroidMisc::DeviceMake; // make of the device we are running on eg. "samsung"
FString FAndroidMisc::DeviceModel; // model of the device we are running on eg "SAMSUNG-SGH-I437"
FString FAndroidMisc::DeviceBuildNumber; // platform image build number of device "R16NW.G960NKSU1ARD6"
FString FAndroidMisc::OSLanguage; // language code the device is set to eg "deu"
FString FAndroidMisc::ProductName; // product/marketing name of the device, if available.

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Android/AndroidPlatformMisc.cpp:1705

Scope (from outer to inner):

file
function     void FAndroidMisc::SetVersionInfo

Source code excerpt:

	AndroidVersion = InAndroidVersion;
	AndroidMajorVersion = FCString::Atoi(*InAndroidVersion);
	TargetSDKVersion = InTargetSDKVersion;
	DeviceMake = InDeviceMake;
	DeviceModel = InDeviceModel;
	DeviceBuildNumber = InDeviceBuildNumber;
	OSLanguage = InOSLanguage;
	ProductName = InProductName;
	UE_LOG(LogAndroid, Display, TEXT("Android Version: %s, Make: %s, Model: %s, BuildNumber: %s, Language: %s, Product name: %s"), *AndroidVersion, *DeviceMake, *DeviceModel, *DeviceBuildNumber, *OSLanguage, ProductName.IsEmpty() ? TEXT("[not set]") : *ProductName);

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Android/AndroidPlatformMisc.cpp:1726

Scope (from outer to inner):

file
function     int32 FAndroidMisc::GetTargetSDKVersion

Source code excerpt:

int32 FAndroidMisc::GetTargetSDKVersion()
{
	return TargetSDKVersion;
}

const FString FAndroidMisc::GetDeviceMake()
{
	return DeviceMake;
}

#Loc: <Workspace>/Engine/Source/Runtime/Core/Public/Android/AndroidPlatformMisc.h:254

Scope: file

Source code excerpt:

	static CORE_API FString AndroidVersion; // version of android we are running eg "4.0.4"
	static CORE_API int32 AndroidMajorVersion; // integer major version of Android we are running, eg 10
	static CORE_API int32 TargetSDKVersion; // Target SDK version, eg 29.
	static CORE_API FString DeviceMake; // make of the device we are running on eg. "samsung"
	static CORE_API FString DeviceModel; // model of the device we are running on eg "SAMSUNG-SGH-I437"
	static CORE_API FString DeviceBuildNumber; // platform image build number of device "R16NW.G960NKSU1ARD6"
	static CORE_API FString OSLanguage; // language code the device is set to
	static CORE_API FString ProductName; // Product name, if available. e.g. 'Galaxy Tab S8' or empty string.

#References in C# build files

This variable is referenced in the following C# build files:

Location: <Workspace>/Engine/Source/Programs/AutomationTool/Android/AndroidPlatform.Automation.cs:1308

		Ini.GetInt32("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "MinSDKVersion", out MinSDKVersion);
		int TargetSDKVersion = MinSDKVersion;
		Ini.GetInt32("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "TargetSDKVersion", out TargetSDKVersion);
		Logger.LogInformation("{Text}", "Target SDK Version " + TargetSDKVersion);
		bool bDisablePerfHarden = false;
        if (TargetConfiguration != UnrealTargetConfiguration.Shipping)
        {
			Ini.GetBool("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "bEnableMaliPerfCounters", out bDisablePerfHarden);
		}

Location: <Workspace>/Engine/Source/Programs/UnrealBuildTool/Platform/Android/UEDeployAndroid.cs:3510

			Ini.GetInt32("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "MinSDKVersion", out MinSDKVersion);
			TargetSDKVersion = MinSDKVersion;
			Ini.GetInt32("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "TargetSDKVersion", out TargetSDKVersion);

			// Check for targetSDKOverride from UPL
			string TargetOverride = UPL.ProcessPluginNode(NDKArch, "targetSDKOverride", "");
			if (!String.IsNullOrEmpty(TargetOverride))
			{
				int OverrideInt = 0;