Programing

Android 에뮬레이터를 사용한 원격 디버깅

lottogame 2020. 9. 14. 21:37
반응형

Android 에뮬레이터를 사용한 원격 디버깅


한 컴퓨터에서 코드를 작성하고 Android 애플리케이션을 컴파일하고 다른 컴퓨터에서 시작한 에뮬레이터에서 원격으로 디버깅 할 수 있습니까? 랩톱 CPU의 절반을 지속적으로 먹는 에뮬레이터가 지겨워 요.


adb connectcmb가 언급 한 명령을 이전에 시도해 본 적이 없거나 알아 차리지 못했지만 SSH를 통해 TCP 포트를 직접 전달하는 것이 제대로 작동하는지 확인할 수 있습니다.

에뮬레이터는 인스턴스 당 2 개의 TCP 포트 (텔넷 인터페이스 용 5554 및 DDMS와 같은 도구와의 제어 통신용 5555)에서 수신 대기합니다. 따라서 포워딩 포트 5555로만 벗어날 수 있습니다 (지금까지는 둘 다 시도해 보았지만). 각 후속 에뮬레이터는 다음으로 사용 가능한 짝수 + 홀수 포트 번호 튜플을 사용합니다 (최대 약 5580).

참고로 로컬 컴퓨터에서 다음 단계를 수행했습니다.

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

에뮬레이터가 시작시 로컬 adb 서버에 알리려고한다고 생각합니다. 따라서 로컬 5554+ 포트를 검색하려면 adb를 다시 시작해야합니다.

점을 유의 localhostssh 명령에서이의 로컬 인터페이스를 지칭 원격 시스템.

adb devices새로운 에뮬레이터를 보여주었습니다 — emulator-5554— 마치 내 로컬 컴퓨터에서 실행되는 것처럼 사용할 수있었습니다.


다음은 Windows에서 해결 한 방법입니다. 나는 크리스토퍼의 리드를 거의 따랐지만 편집 할 수 없으므로 새로운 답변이 필요합니다.

내가 가진 문제는 ADB와 에뮬레이터가 0.0.0.0이 아닌 127.0.0.1에서 듣고 있다는 것입니다. 그렇지 않으면 TCPMon 을 사용했을 것 입니다. Windows에서 다르거 나 최신 버전의 SDK에서 변경된 것 같습니다. (으로 확인할 수 있습니다 netstat -ban.)

  1. 에뮬레이터를 실행하는 컴퓨터에 WinSSHD설치했습니다 . (freeSSHd에서도 작동해야한다고 생각하지만 거기에서 작동하는 로그인을 얻을 수 없습니다.)

  2. Windows 방화벽에서 포트 22 (TCP)를 열었습니다. (WinSSHD가이를 수행 할 수 있습니다.)

  3. WinSSHD GUI에서 가상 계정을 만들었습니다.

  4. 개발 머신에서 에뮬레이터 머신으로 새로운 PuTTY 연결을 만들고 연결할 수 있는지 확인했습니다.

  5. 그런 다음 PuTTY에서 터널링을 설정했습니다. 연결-> SSH-> 터널

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

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

    (터널을 유지하려면 PuTTY를 연결하고 열어 두십시오.)

  6. 이제 원격 컴퓨터에서 에뮬레이터를 실행하고 ADB가 실행되고 있지 않은지 확인했습니다.

  7. 개발 머신에서 ADB를 다시 시작했습니다 ( adb kill-server, adb start-server).

  8. adb devices원격 에뮬레이터는 emulator-5554 device. 이제 Eclipse / ADT에서 직접 앱을 배포하고 실행할 수 있습니다. 여기에서 에뮬레이터는 마치 로컬 에뮬레이터 인 것처럼 가상 장치 아래에 표시되었습니다.


이 질문이 정말 오래되었다는 것을 알고 있지만 문제를 약간 다르게 해결했고이 사소한 해결책을 찾는 데 시간이 걸렸습니다.

나는 GUI를 좋아하기 때문에 일반적으로 Windows7 PC 또는 랩톱 (작업중인 위치에 따라 다름)을 프런트 엔드로 사용하지만 모든 편집 / 컴파일 / 디버그를 헤드리스 Ubuntu 서버에서 수행하는 것을 선호합니다. 제공하는 명령 줄 기능. 내 목표는 각 Windows 시스템을 추가 서비스 (예 : sshd) 나 방화벽 구멍없이 가능한 한 씬 클라이언트로 만드는 것입니다.

그래서 여기에 시나리오가 있습니다.

  • System-A : Android 에뮬레이터가 실행중인 Windows7 시스템
  • System-B : SDK가 설치된 Ubuntu 서버

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

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.


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>

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.


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).


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.

참고URL : https://stackoverflow.com/questions/1754162/remote-debugging-with-android-emulator

반응형