在安卓模拟器上打开待测应用
在shell窗口输入
adb shell dumpsys window | grep mCurrentFocus
(windows系统将grep替换成findstr)
会得到待测应用的appPackage和appActivity
比如得到输出mCurrentFocus=Window{9a14051 u0 com.vmware.view.client.android/com.vmware.view.client.android.BrokerAddressPrompt}
那么apppackage就是com.vmware.view.client.android,appActivity就是com.vmware.view.client.android.BrokerAddressPrompt或者直接写.BrokerAddressPrompt
修改安卓模拟器hosts文件
参考:How to edit /etc/hosts file in Android Studio emulator running in nougat?
步骤:
使用安卓自带的emulator启动模拟器,注意要加上-writable-system参数(否则后面adb remount会failed)
/Users/username/Library/Android/sdk/emulator/emulator -avd Pixel_2_API_31 -writable-system
adb root adb remount
使用自己修改好的hosts文件替换安卓里面的hosts文件
adb push /Users/username/Desktop/hosts /system/etc/hosts
验证修改结果:
进入安卓命令行
adb shell
查看安卓hosts文件
cat /system/etc/hosts
自己写的hosts文件内容
127.0.0.1 localhost ::1 ip6-localhost 10.0.2.2 test-server.local
主要是添加了最后一行
10.0.2.2是安卓模拟器连接PC的 127.0.0.1地址的方式,具体参考:why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client



