{"record":{"id":"3fa49abea9dee4b9","repo":"expo/expo","slug":"expo-adb-user","errorCode":"EXPO_ADB_USER","errorMessage":"Invalid ADB user number \"${userNumber}\" set with environment variable EXPO_ADB_USER. Run \"adb shell pm list users\" to see valid user numbers.","messagePattern":"Invalid ADB user number \"(.+?)\" set with environment variable EXPO_ADB_USER\\. Run \"adb shell pm list users\" to see valid user numbers\\.","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"packages/@expo/cli/src/start/platforms/android/ADBServer.ts","lineNumber":112,"sourceCode":"        stdio: 'pipe',\n      })\n    );\n    event('adb_file_output', { output: results });\n    return results;\n  }\n\n  /** Formats error info. */\n  async resolveAdbPromise<T>(promise: T | Promise<T>): Promise<T> {\n    try {\n      return await promise;\n    } catch (error: any) {\n      // User pressed ctrl+c to cancel the process...\n      if (error.signal === 'SIGINT') {\n        throw new AbortCommandError();\n      }\n      if (error.status === 255 && error.stdout.includes('Bad user number')) {\n        const userNumber = error.stdout.match(/Bad user number: (.+)/)?.[1] ?? env.EXPO_ADB_USER;\n        throw new CommandError(\n          'EXPO_ADB_USER',\n          `Invalid ADB user number \"${userNumber}\" set with environment variable EXPO_ADB_USER. Run \"adb shell pm list users\" to see valid user numbers.`\n        );\n      }\n      // TODO: Support heap corruption for adb 29 (process exits with code -1073740940) (windows and linux)\n      let errorMessage = (error.stderr || error.stdout || error.message).trim();\n      if (errorMessage.startsWith(BEGINNING_OF_ADB_ERROR_MESSAGE)) {\n        errorMessage = errorMessage.substring(BEGINNING_OF_ADB_ERROR_MESSAGE.length);\n      }\n\n      error.message = errorMessage;\n      throw error;\n    }\n  }\n}\n","sourceCodeStart":94,"sourceCodeEnd":128,"githubUrl":"https://github.com/expo/expo/blob/b09195aac27c9e4a63daaf12dcb6f00b6b2e08ee/packages/@expo/cli/src/start/platforms/android/ADBServer.ts#L94-L128","documentation":"Thrown by ADBServer.resolveAdbPromise (code EXPO_ADB_USER) when an adb command fails with exit status 255 and its stdout contains 'Bad user number'. This indicates the Android multi-user number configured via the EXPO_ADB_USER environment variable is invalid for the connected device/emulator. The error extracts the offending number from adb's output (or falls back to env.EXPO_ADB_USER) and points the user to list valid users.","triggerScenarios":"An adb invocation run through resolveAdbPromise rejects with error.status === 255 and error.stdout includes 'Bad user number', which happens when EXPO_ADB_USER points to a user id that doesn't exist on the device (e.g. using --user 999 on a single-user emulator).","commonSituations":"EXPO_ADB_USER set globally to a value valid on one device but not another. Copying an env var from a multi-user Android device to a single-user emulator. A stale .env or shell profile with an old user number. A device whose user list changed after a factory reset.","solutions":["List valid users: `adb shell pm list users` and note a valid user id (usually 0).","Set EXPO_ADB_USER to a valid id, e.g. `export EXPO_ADB_USER=0`, or unset it to use the default.","Remove the EXPO_ADB_USER line from your shell profile/.env if you don't need multi-user targeting.","Reconnect the device and recheck users, since user ids can change after resets."],"exampleFix":"// before: export EXPO_ADB_USER=10   # invalid on this device\n// after:  export EXPO_ADB_USER=0","handlingStrategy":"validation","validationCode":"import { env } from '../../utils/env';\nimport { executeAdbAsync } from './adb';\n\nasync function isValidAdbUser(user: string | undefined): Promise<boolean> {\n  if (!user) return true;\n  const out = await executeAdbAsync(['shell', 'pm', 'list', 'users']);\n  return new RegExp(`UserInfo\\\\{${user}:`).test(out);\n}\n\nif (!(await isValidAdbUser(env.EXPO_ADB_USER))) {\n  throw new Error(`EXPO_ADB_USER=${env.EXPO_ADB_USER} is not a valid user id on this device.`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await adbServer.resolveAdbPromise(someAdbCall);\n} catch (e: any) {\n  if (e.code === 'EXPO_ADB_USER') {\n    // unset EXPO_ADB_USER or set it to 0, then retry\n  } else throw e;\n}","preventionTips":["Leave EXPO_ADB_USER unset unless you target a specific Android multi-user.","Verify with `adb shell pm list users` before setting the env var.","Don't copy EXPO_ADB_USER across devices with different user configurations."],"tags":["android","adb","env-variable","multi-user","device"],"backgroundTag":null,"analyzedSha":"b09195aac27c9e4a63daaf12dcb6f00b6b2e08ee","analyzedAt":"2026-08-12T15:59:58.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}