Problem found. Unfortunately it is deep in the emulator (qemu) startup code. The following code registers the emulator instance with the adb server.
socket_send(s, tmp, 18+4);
This registers the emulator with the adb server but it makes two assumptions:
- that the user port is one less than the adb port for the emulator. Comments in the code also suggest that the user port was once assumed to be an even number. The server takes the adb port number supplied and subtracts one to get the user port. It then tries to connect to the user port to confirm that it really is an emulator.
- only 4 characters of the adb port number is sent to the adb server (the +4 in socket_send). Thus if the port number is greater than 9999 or less than 1000 then the wrong port number is sent.
I haven't searched the Android bug database for this yet but will search/report there later today.
However that does not make things work for a-e-p because we will need to support older emulators.
I tested a fix that uses the Jenkins port allocator to allocate 7000 for user port, 7001 for emulator adb port and then 8000 for the adb server. With that maven happily worked using -Dandroid.device=emulator.
[INFO] Found 1 devices connected with the Android Debug Bridge
[INFO] android.device parameter set to emulator
[INFO] checking device=emulator-6000_hudson_en-GB_160_WVGA_android-7_unknown_sdk, port=8000, name=hudson_en-GB_160_WVGA_android-7, isEmulator=true
[INFO] Emulator emulator-6000_hudson_en-GB_160_WVGA_android-7_unknown_sdk found.
Obviously to provide a proper fix we need to do some magic with the port allocator plugin. Assuming that it is acceptable that we require a newer port allocator plugin for a-e-p then I'll look to extend that to help us. Failing that we can likely make the existing allocator work with a bit of messing around.