Android Emulators, or What’s So Special about the Number 5554?
When you launch an Android device emulator, the new emulator’s name is something like emulator-5554 or emulator-5556. The name stems from the fact that each run of an Android emulator uses two port numbers (two channels for communicating with the development computer).
As you may already know, your web browser normally uses port number 80 to request a web page. Your email program probably uses port 110, port 143, port 585, port 993, or port 995 to retrieve email.
When you launch an emulator on your development computer, you can specify several port numbers for several of the emulator’s networking needs. Most of the time, you start an emulator without explicitly specifying port numbers. When you don’t specify port numbers, your emulator relies on default values. If you ever specify a port number other than the default, you do so because you don’t want the emulator’s communications to conflict with some other program’s use of a particular port number.
Who knows? Maybe your favorite computer game talks to the web over port 5228, the port number Android uses to obtain apps from the Google’s Play Store.
Now imagine that you have no emulators running on your development computer, and you start an emulator without specifying any port numbers. Then the new emulator uses two default port numbers — 5554 and 5555.
The emulator uses port 5554 to relay its console messages (the text that appears in Eclipse’s Console view).
The emulator uses port 5555 to talk to the Android Debug Bridge (adb). For example, when you type adb install myApp.apk in your development computer’s command window, the Android Debug Bridge installs myApp.apk onto your running emulator using port 5555 to handle the communications.
If you type the command adb devices in your development computer’s command window, you see a list of running emulators. (The list also includes any actual devices that are plugged into your computer via USB or some other fancy connection.) The list probably includes emulator-5554 because 5554 is the default console port number, and an emulator’s name comes from the emulator’s console port number (not from the emulator’s adb port number, which in this example is 5555).
Time to raise the ante. Imagine that with emulator-5554 running, you go back to your development computer and start a second emulator (again, without explicitly specifying any port numbers). Then Android launches a new emulator with console port 5556 and adb port 5557. The adb port number is always one more than the console port number.
To install myApp.apk on the second of the two running emulators, you’d type adb -s emulator-5556 install myApp.apk in your development computer’s command window. If you close the first emulator, the second emulator’s port numbers don’t change. So after closing the first of the two emulators, when you type adb devices, the list of devices includes emulator-5556 and no longer includes emulator-5554.
The allowable console port numbers for Android emulators are the even numbers from 5554 to 5584 inclusive. So you can simultaneously run emulators named emulator-5554, emulator-5556, emulator-5558, and so on up to emulator-5584.