Remote debugging with Android emulator

前端 未结 8 1089
耶瑟儿~
耶瑟儿~ 2020-11-30 17:09

Is it possible to write the code/compile Android application on one machine and debug it remotely on the emulator launched on another? I\'m sick and tired of the emulator co

8条回答
  •  广开言路
    2020-11-30 17:30

    I found an easy way to do this if your two machines are in the same private network and therefore do not need to use SSH encryption (which is the common case). This may help as an SSH tunnel can be quite long and difficult to install. For example, installing an SSH daemon under Cygwin / Windows for the first time may lead to give up (well, I gave up).

    Under Windows, what follows requires having Cygwin installed with the package httptunnel. This must work under Linux / httptunnel as well but I didn't try.

    • Run the emulator on one of the machines (let's say its host name is HostEmulator)

    • Start Eclipse on the other machine (let's call it HostEclipse)

    • Open a Cygwin terminal on each machine, and then,

    • On HostEmulator, enter the following cygwin commands:

      hts -F localhost:5554 10000
      hts -F localhost:5555 10001
      

    hts means Http Tunnel Server.

    These two commands create two half-bridge that listen to the ports 10001 and 10001 and that redirect the I/O of these ports to the local ports 5554 and 5555, which are the ports used by the emulator (actually, the first lauched emulator - if you are several of them running they will use higher port numbers as seen in other replies of this page).

    • On HostEclipse, enter these ones:

      htc -F 5554 HostEmulator:10000
      htc -F 5555 HostEmulator:10001
      

    htc means Http Tunnel Client.

    These commands create the missing half-bridges. They listen to the local ports 5554 and 5555 and redirects the I/O of these ports to the half-bridges we have created on HostEmulator just before.

    • Then, still on HostEclipse, enter these three commands:

      adb kill-server
      adb start-server
      adb devices
      

    This restarts adb as it doesn't detect the remote emulator otherwise. It must be doing some scanning at startup. And then it lists the devices (the available emulators) just for checking.

    • And there you go.

    You can work with your remote emulator as if it was local. You have to keep the Cygwin terminals open on both machine otherwise you would kill the half bridges you created.

    I used the port 10000 and 10001 for the machine/machine exchanges here, but of course you can use other ports as long as they are not already in use.

提交回复
热议问题