Search code examples
android-studioadb

how to map Android Studio device name to ADB device name?


In Android Studio's Device Manager, the virtual device name is

New Device API 30 1 

After I launched it from Android Studio, I can see it in 'adb devices' output as

C:\>adb devices
List of devices attached
emulator-5554   device

If I only have one device running, there is no confusion.

If I have multiple, is there a way to tell which is which?

Background

when I start emulator in a script, I need to use the Android Studio device name.

emulator -avd New_Device_API_30_1

but when I connect my Appium Python client to Appium server, I need to use the ADB device name in desired_cap

driver = webdriver.Remote(f"http://127.0.0.1:4723/wd/hub", {"appium:deviceName":"emulator-5554", ...})

I need to automate these two steps.

Thank you


Solution

  • You can specify the port when you start the emulator then you will know the device name

    emulator -avd New_Device_API_30_1 -port 5558
    

    then you will see

    adb devices
    List of devices attached
    emulator-5558   device
    

    otherwise they will be selected in the order they are started.