Yotes
Yotes

Reputation: 378

Install Apk in specific emulator

Im trying to install an apk on an specific emulator using TeamCity. Right now I`m starting an emulator an installing the apk successfully.. but if there is already one or more instances of the emulator running, team city cannot decide in which emulator install the apk (even when I'm starting the emulator from teamcity scripts).

The problem is that I cannot identify the emulator I just started using:

emulator -adv myEmulator

it will start an emulator between ports 5554 to 5587... I know I can set the emulator instance where I want to install my apk:

adb -s emulator-5554 install path/apk

but I don't know the id of the emulator I just started, so it could have any number in its name between that range.

I know I can set an UUID to the emulator (from here), but again.. don't know how to use that uuid.

Right now I will try to save the available emulators before I run my own using BATCH, and then compare both arrays to get my emulator.. but I'm not an expert on BATCH.. so if anyone has a clue it's gonna help,

Regards

Upvotes: 2

Views: 2339

Answers (1)

Marcin Orlowski
Marcin Orlowski

Reputation: 75619

You seem to look for -s option of adb:

   -s <specific device>       - directs command to the device or emulator with
                                the given serial number or qualifier.

other useful options:

   -d                         - directs command to the only connected USB device
                                returns an error if more than one USB device is
                                present.
   -e                         - directs command to the only running emulator.
                                returns an error if more than one emulator is
                                running.

and in general adb -h to see them all.

EDIT

You can define what port you want emulator to use:

-ports <consoleport>,<adbport> TCP ports used for the console and adb bridge

so you can assign ports manually and do not bother guessing. to avoid port collisions you can either force ports for all emulators launched (you should not have more than i.e. 3 running at the same time usually) or you can choose high port numbers for your range, high enough so even any other emulator is launched it will be using available ports below your range.

Alternatively you can parse emulator log produced when use with -verbose switch as you can find there:

emulator: control console listening on port 5554, ADB on port 5555
emulator: sent '0012host:emulator:5555' to ADB server

If you want to save emulator log to specific file, use regular stream redirection:

emulator -verbose @MyAVD > log.txt

Upvotes: 4

Related Questions