androidexpoadb

How to tell expo to use a certain emulator (or to skip a broken one)?


I have difficulties running our expo project on Android emulator. In principle it works, but I have a dead, broken emulator device in adb devices which I cannot get rid of (I think I tried everything... probably it is a remainder of my recent system migration to a new Macbook).

And expo is trying to get the AVD name of this, which crashes then.

> DEBUG=expo:* npx expo start --dev-client --clear -a
...
...
  expo:start:platforms:android:adbServer /Users/paul/Library/Android/sdk/platform-tools/adb devices -l +0ms
  expo:start:platforms:android:adbServer /Users/paul/Library/Android/sdk/platform-tools/adb -s emulator-5554 emu avd name +14ms
  expo:start:platforms:android:adbServer /Users/paul/Library/Android/sdk/platform-tools/adb -s emulator-5562 emu avd name +1ms
Error: could not connect to TCP port 5562: Connection refused
Error: /Users/paul/Library/Android/sdk/platform-tools/adb -s emulator-5562 emu avd name exited with non-zero code: 1

Can I somehow tell expo to use the working one (5554) as default and skip any interaction with the broken one (5562)?

We are running expo 53, my expo-cli is 0.24.

> npx expo -version
0.24.21

My adb devices -l shows:

➤ adb devices -l
List of devices attached
emulator-5554          device product:sdk_gphone64_arm64 model:sdk_gphone64_arm64 device:emu64a transport_id:55
emulator-5562          offline transport_id:311

Sometimes, when disconnecting a real device this offline entry disappears for a fraction of a second before re-appearing. There is no AVD for this. I already uninstalled and reinstalled everything related.

I can workaround this issue running the expo apk on my emulator and connecting it with my host. But it really would be easier if I could start it directly from the project.


Solution

  • After starting expo you can press Shift + A to select an Android device or emulator to open. (Same Shift + I for ios)

    To delete the broken emulator you can use the Android Studio device manager:

    enter image description here

    If you want to start expo with a specific emulator (in your case "emulator-5554") you can use npx expo run:android --device emulator-5554

    If this is not possible and you still have the zombie emulator it most likely comes from a NTKDaemon process. Try to kill any of them:
    killall NTKDaemon 2>/dev/null || true
    Also try to kill all emulator processes:
    pkill -f "qemu-system" 2>/dev/null || true pkill -f "[e]mulator" 2>/dev/null || true

    Than it should be gone. If you dont need the NTKDaemon you can disable it:
    launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/com.native-instruments.NTKDaemon.plist 2>/dev/null

    sudo launchctl bootout system /Library/LaunchDaemons/com.native-instruments.NTKDaemon.plist 2>/dev/null

    There is no option to ignore "offline devices" but you can try to pin to the right emulator:
    export ANDROID_SERIAL=emulator-5554