Remote debugging with Android emulator

前端 未结 8 982
耶瑟儿~
耶瑟儿~ 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:14

    I don't have a second machine with the SDK to hand, but I note that the emulator's listen ports (default 5554, 5555) are listening on 0.0.0.0, i.e. reachable from remote machines, and that adb --help shows a connect <host>:<port> command. I assume that would make it show up in adb devices so adb commands work on it. For Eclipse, try "Run / Run Configurations..." and set the Target to Manual. That gives you a "device chooser" which I'm guessing would include a remote emulator if adb is connected to it. Worth a try.

    0 讨论(0)
  • 2020-11-30 17:22

    I haven't previously tried (or even noticed) the adb connect command that cmb mentioned, but I can confirm that forwarding the TCP ports yourself — such as over SSH — works fine.

    The emulator listens on two TCP ports per instance: 5554 for the telnet interface and 5555 for control communication with tools like DDMS. So you could probably get away with only forwarding port 5555 (though I've only tried it so far with both). Each subsequent emulator takes the next available even+odd port number tuple (up to around 5580, I think).

    For reference, I did the following steps on my local machine:

    • ssh -NL 5554:localhost:5554 -L 5555:localhost:5555 myuser@remote-server
    • killall adb; adb devices

    I believe the emulator tries to notify a local adb server at startup; hence the need to restart adb in order for it to probe the local 5554+ ports.

    Note that the localhost in the ssh command refers to the local interface of the remote machine.

    adb devices showed a new emulator — emulator-5554 — and I could use it as if it were running on my local machine.

    0 讨论(0)
  • 2020-11-30 17:24

    None of the proposed solutions worked for me. I've started from Emirikol's solution and refined it, as with the new Android API > 21 the emulator was appearing offline and I had to go to Genymotion settings and leave Android SDK path empty. And from command line:

    netsh interface portproxy add v4tov4 listenport=5555 connectport=5555 connectaddress=<emulatorIP>
    
    netsh interface portproxy add v4tov4 listenport=5554 connectport=5554 connectaddress=<emulatorIP>
    

    source:http://www.sarpex.co.uk/index.php/2016/10/02/connect-genymotion-emulator-remotely/ Disclaimer, I'm the author.

    0 讨论(0)
  • 2020-11-30 17:26

    Here is how I solved it on Windows. I pretty much followed Christopher's lead, but I can't edit, so a new answer will have to do.

    The problem I had was that ADB as well as the emulator was just listening on 127.0.0.1, not 0.0.0.0, for me. Otherwise I would have used TCPMon. I guess this is either different on Windows, or has changed with the latest versions of the SDK. (You can check with netstat -ban.)

    1. I installed WinSSHD on the machine that runs the emulator. (I believe it should work with freeSSHd as well, but I couldn't get a login working there.)

    2. I opened port 22 (TCP) in the Windows Firewall. (WinSSHD might be able to do that for you.)

    3. I created a virtual account in the WinSSHD GUI.

    4. I created a new PuTTY connection from the development machine to the emulator machine and made sure I could connect.

    5. Then I set up tunnelling in PuTTY: Connection -> SSH -> Tunnels

      Source port: 5554
      Destination: localhost:5554
      Type: Local/Auto

      Source port: 5555
      Destination: localhost:5555
      Type: Local/Auto

      (Connect and keep PuTTY open, to maintain the tunnel.)

    6. Now I fired up the emulator on the remote machine and made sure that ADB is not running there.

    7. I restarted ADB on the development machine (adb kill-server, then adb start-server).

    8. adb devices and the remote emulator showed up as emulator-5554 device. I could now deploy and run my app straight from Eclipse/ADT, where the emulator showed up under Virtual Devices as if it was a local emulator.

    0 讨论(0)
  • 2020-11-30 17:28

    My solution for windows + AndroVM (which requires a host-only adapter) when my ssh service failed to start. so it doesn't require any additional software.

    adb connect <Andro VM IP>
    adp tcpip 555
    

    On cmd prompt run as admin:

    netsh interface portproxy add v4tov4 listenport=5555 listenaddress=<host ip> connectport=5555 connectaddress=<Andro VM IP>
    

    open TCP port 5555 in windows firewall.

    Then, from the second PC run:

    adb connect <host ip>
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题