dotnet/maui · error · Exception

Unexpected platform (expected: android) in device: {deviceDe

Error message

Unexpected platform (expected: android) in device: {deviceDescriptor}

What it means

Thrown while parsing a device descriptor string when the first hyphen-delimited segment is not 'android'. The descriptor format is '<platform>-<deviceType>-<bits>[_<apiLevel>]' (e.g. android-emulator-64_30), and the platform token must be exactly 'android'.

Source

Thrown at eng/devices/android.cake:392

	return settings;
}

void DetermineDeviceCharacteristics(string deviceDescriptor, int defaultApiLevel)
{
	var isArm64 = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.Arm64;
	var working = deviceDescriptor.Trim().ToLower();
	var emulator = true;
	var api = defaultApiLevel;
	// version
	if (working.IndexOf("_") is int idx && idx > 0)
	{
		api = int.Parse(working.Substring(idx + 1));
		working = working.Substring(0, idx);
	}
	var parts = working.Split('-');
	// os
	if (parts[0] != "android")
		throw new Exception("Unexpected platform (expected: android) in device: " + deviceDescriptor);
	// device/emulator
	Information("Create for: {0}", parts[1]);
	if (parts[1] == "device")
		emulator = false;
	else if (parts[1] != "emulator" && parts[1] != "simulator")
		throw new Exception("Unexpected device type (expected: device|emulator) in device: " + deviceDescriptor);
	// arch/bits
	Information("Host OS System Arch: {0}", System.Runtime.InteropServices.RuntimeInformation.OSArchitecture);
	Information("Host Processor System Arch: {0}", System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture);
	if (parts[2] == "32")
	{
		if (emulator)
			deviceArch = "x86";
		else
			deviceArch = "armeabi-v7a";
	}
	else if (parts[2] == "64")
	{

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Use a descriptor starting with 'android-', e.g. android-emulator-64_30 or android-device-64.
  2. Check the ANDROID_TEST_DEVICE env var / --device argument for typos or wrong-platform values.
  3. Ensure the CI matrix job that targets Android passes Android-formatted descriptors only.

Example fix

# before
--device=ios-simulator-64
# after
--device=android-emulator-64_30
Defensive patterns

Strategy: validation

Validate before calling

var parts = deviceDescriptor.Trim().ToLower().Split('-');
if (parts.Length < 3 || parts[0] != "android")
    throw new Exception($"Invalid device descriptor '{deviceDescriptor}'. Expected format: android-<device|emulator>-<32|64>[_<apiLevel>]");

Type guard

bool IsValidAndroidDescriptor(string d) {
    if (string.IsNullOrWhiteSpace(d)) return false;
    var p = d.Trim().ToLower().Split('-');
    return p.Length >= 3 && p[0] == "android";
}

Prevention

When it happens

Trigger: A device descriptor whose lowercased first segment (parts[0]) is not 'android' — e.g. 'ios-simulator-64', 'win-device-x64', or a typo like 'androi-emulator-64'.

Common situations: Passing a device string formatted for a different platform (iOS/Catalyst/Windows) into the Android device helper; a typo in the device name; a CI matrix variable injecting the wrong platform descriptor.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/37aeb1d8f1d87996. Report an issue: GitHub.