Remote debugging with Android emulator

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

    I realize this question is really old, but I solved the problem slightly differently, and it took me a while to figure out this trivial solution.

    I usually use a Windows7 PC or laptop (depending on where I'm working) as my front-end because I like the GUI, however I prefer to do all of my edit/compile/debug on a headless Ubuntu server because of all the command-line power it provides. My goal is to make each windows system as much of a thin-client as possible without any extra services (such as sshd) or firewall holes.

    So here is the senario:

    • System-A: Windows7 system with android emulator running
    • System-B: Ubuntu server with SDK installed

    The problem as described earlier is that the emulator on System-A binds to localhost, not the external ethernet interface, so adb on the System-B cannot access the emulator on System-A. All you need to do is set up remote port forwarding in PuTTY for your SSH connection to System-B. The trick is to check the "Remote" radio button when you create the two tunnels so that the tunnel direction is reversed (tunneling from the server you are logging into to the client you are logging in from).

    tunnel screenshot

    Finally, connect with adb to "localhost" on System-B after establishing the SSH connection:

    System-B$ adb connect localhost
    connected to localhost:5555
    System-B$ adb devices
    List of devices attached
    localhost:5555  device
    

    Now you can download images/debug as normal, and it is a trivial matter to switch to a different Windows system if you want to take your laptop out and get some coffee.

    In addition, by also tunneling port 5037 in the same manner you can actually forward your adb server connection so that you can connect a real android device over USB on System-A, and download images to it from System-B. In order for this to work, you need to make sure that the adb server is running on System-A, and not running on System-B before starting your SSH session:

    First, start the adb server on System-A (command prompt)

    C:\> adb start-server
    * daemon not running. starting it now on port 5037 *
    * daemon started successfully *
    C:\> adb devices
    List of devices attached
    3435F6E6035B00EC        device
    

    Next, kill the adb server on System-B

    System-B$ adb kill-server
    

    Finally, restart your ssh session to System-B and verify

    System-B$ adb devices
    List of devices attached
    3435F6E6035B00EC        device
    
    0 讨论(0)
  • 2020-11-30 17:33

    When you run adb, it starts a server copy of itself if one isn't already running. You can start that copy yourself on the machine with the device and since sdk 4.3 you can give it the -a option to tell that server to listen for remote machines. Do that with the following command which doesn't exit:

    adb -a -P 5037 server nodaemon

    On the machine you want to use the device from, set ADB_SERVER_SOCKET to tcp:xxxx:5037 in an environment variable (or give the same value to each adb invocation with the -L option), where xxxx is the IP address or hostname of the machine with the devices, and 5037 matches the port you gave the in the command above.

    We use this to give access to about 100 emulators spread over 3 machines to a machine running end to end tests in parallel, and to developers wanting to share real devices remotely.

    You can forward ports to and from the emulator with adb forward and adb reverse, and they'll appear on the machine with the devices (not the machine you're running 'adb forward' from).

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