dotnet/maui · error · Exception
Unexpected device type (expected: device|emulator) in device
Error message
Unexpected device type (expected: device|emulator) in device: {deviceDescriptor} What it means
Thrown while parsing a device descriptor when the second segment (device type) is not one of 'device', 'emulator', or 'simulator'. After confirming the platform is android, the parser expects a concrete device-kind token.
Source
Thrown at eng/devices/android.cake:398
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")
{
if (isArm64)
deviceArch = "arm64-v8a";
else if (emulator)
deviceArch = "x86_64";
else
deviceArch = "arm64-v8a";View on GitHub (pinned to f377ff1c5e)
Solutions
- Use 'device' for a physical Android device or 'emulator' for an Android emulator in the descriptor.
- Correct typos in the ANDROID_TEST_DEVICE env var / --device argument.
- Refer to the parser's accepted tokens: device | emulator (simulator also accepted).
Example fix
# before --device=android-phone-64_30 # after --device=android-device-64_30
Defensive patterns
Strategy: validation
Validate before calling
var validTypes = new[] { "device", "emulator", "simulator" };
if (!validTypes.Contains(parts[1]))
throw new Exception($"Invalid device type '{parts[1]}'. Expected one of: {string.Join("|", validTypes)}."); Type guard
bool IsValidDeviceType(string descriptor) {
var p = descriptor.Trim().ToLower().Split('-');
return p.Length >= 2 && new[]{"device","emulator","simulator"}.Contains(p[1]);
} Prevention
- List accepted tokens in the error message itself.
- Validate the whole descriptor up front rather than failing mid-parse.
- Add a unit-style test over the descriptor parser for each accepted shape.
When it happens
Trigger: parts[1] is something other than 'device', 'emulator', or 'simulator' — e.g. 'android-phone-64' or 'android-real-64'. (Note 'simulator' is accepted but semantically unusual for Android.)
Common situations: Typo in the device type token (phone, real, phys instead of device); copying a descriptor format from another system; an outdated descriptor after the format changed.
Related errors
- Unexpected platform (expected: android) in device: {deviceDe
- Environment variable 'ANDROID_SDK_ROOT' or 'ANDROID_HOME' mu
- JAVA_HOME environment variable isn't set. Set it to your JDK
- UI Test application path not specified.
- The emulator did not finish booting in time.
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/07e77b393411f412.
Report an issue: GitHub.