Search code examples
androiddebuggingadb

Automatically forward port on start?


I need to forward a port on an android emulator, right now I had to type the command every time:

adb forward tcp:23946 tcp:23946

Is there any way to make this automatic? I tried to replace adb with a script but that command won't work until the device is up and running.

Any ideas?


Solution

  • Based on this answer (which I've tested and works, though it wasn't for a scenario like this one), you could simply write a script that waits until the emulator is booted.

    Something like (pseudocode, don't know which platform you're on) :)

    emulator @emulator-name
    while ('adb shell getprop init.svc.bootanim' == "running") sleep(10s)
    adb forward tcp:23946 tcp:23946