Skip to content

Commit

Permalink
[JENKINS-11952] Return to the "localhost:XXXX" style of connecting to…
Browse files Browse the repository at this point in the history
… emulators.

For some reason, connecting to the emulator in this manner appears to be
somwehat more reliable than connecting with the regular "emulator-XXXX" style.

From the various JIRA issues opened against the most recent plugin releases,
this instability seems to affect Mac OS X more than other operating systems.

Now we use "localhost:XXXX", while sticking to a four-digit port number, as some
tools seem to assume that the emulator port is always four-digits.

While it's still a problem that ddmlib — as used by tools like the Maven Android
plugin — only recognise emulators with the "emulator-XXXX" scheme, this should
not be a problem, as the emulator itself at startup registers with adb in this
style.  While this means that running "adb devices" may show two connected
devices (e.g. "emulator-5554" and "localhost:5555"), libraries like ddmlib will
use the "emulator" variant, while build steps that call `adb` will automatically
read the ANDROID_SERIAL environment vairable and use the "localhost" variant.
  • Loading branch information
orrc committed Feb 13, 2015
1 parent 053d17f commit 7949052
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -46,16 +46,16 @@ public AndroidEmulatorContext(AbstractBuild<?, ?> build_,

final Computer computer = Computer.currentComputer();

// Use the Port Allocator plugin to reserve the two ports we need
// Use the Port Allocator plugin to reserve the ports we need
portAllocator = PortAllocationManager.getManager(computer);
final int PORT_RANGE_START = 5560;
final int PORT_RANGE_END = 5900;
final int PORT_RANGE_START = 5554;
final int PORT_RANGE_END = 9999; // Make sure the port is four digits, as there are tools that rely on this
int[] ports = portAllocator.allocatePortRange(build, PORT_RANGE_START, PORT_RANGE_END, 3, true);
userPort = ports[0];
adbPort = ports[1];
adbServerPort = ports[2];

serial = "emulator-" + userPort;
serial = String.format("localhost:%d", adbPort);
}

public void cleanUp() {
Expand Down

0 comments on commit 7949052

Please sign in to comment.