Emulator networking ip address and virtual router

ぃ、小莉子 提交于 2019-12-04 10:45:37

I have the same issue running Android 7.1.1 (API 25) on Windows. But when I emulating Android 7.0 (API 24) it works as expected. Device gets IP 10.0.2.15. In this case ip route show will bring 10.2.x.x address. So, if you can just use prior versions (API 16 - API 24).

This router exists inside emulator and Windows is not aware about it. If you need to access service running inside emulator from Windows, you need to add port mappings:

telnet localhost 5554
auth <token from 'C:\Users\{user}\.emulator_console_auth_token'>
redir add tcp:8080:8080

Then you can access your service by: 127.0.0.1:8080. However, this approach does not work with Android 7.1.1. I have no ideas what is wrong with it.

It appears that since API 25, the networking of an emulator has changed. The device IP is no longer 10.0.2.15, and issuing a 'redir' command via telnet, as it is documented, no longer work.

In order to have a redirection, use the adb program. First, make sure adb is in your earch path. Typically, it is under Android/Sdk/platform-tools, wherever the Android SDK is located, whatever OS you are using.

Then, use the following command line:

adb forward tcp:<host port> tcp:<guest port>

(For example: adb forward tcp:8080 tcp:8080). Now, you can access port with: telnet localhost <host port>, which will be redirected to the guest.

This is very unfortunate, because (as of build 28) it isn't documented this way. I assume at some point documentation will be fixed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!