Disconnect the network in the Android emulator, keeping adb alive

I made a mistake somewhere in my code that my Android application will work when I turn off the network in the emulator, while the HTTPClient application makes a request.

But I can’t debug it, because when I disconnected the network, I also lost the ADB connection. Thus, I do not see which exception is causing the crash.

I tried disconnecting the network:

  • F8
  • Set "Data" to "Unregistered" or "Denied" in the management of the DDMS emulator.

I can put my Mac offline and ADB will not work, but unfortunately I cannot reproduce this failure.

Is there a way to disable the network in the emulator while keeping the ADB alive? I mainly need access to LogCat records.

Thanks!

+6
source share
4 answers

You can run logcat from a device, not from ADB, and redirect it to a file for offline reading.

adb shell logcat [-v threadtime] > /sdcard/mylogs/logcat.log 

Instead

 adb logcat [-v threadtime] 

Then you can get the file when reconnecting to the device.

+2
source

On Linux, this is pretty simple with the iptables firewall. I suppose you are trying to debug API calls, so just block the API host:

 iptables -I OUTPUT -d api.example.com -j DROP 

Of course, you can do the same with a Mac or Windows Firewall.

+1
source

You can always put the device in airplane mode, which will still allow you to connect via adb, but not let the emulator connect to the Internet. You can also disable data through eclipse through the emulator control section in ddms by placing unregistered / denied data loss.

0
source

I know this is an old question, but someone can use find to do this.

My setting

Eclipse Kepler with emulated android 4.4

If you want your adb to be alive and your network disconnected, you can try this.

  • Run emulated device
  • Activate airplane / airplane mode
  • Restart Eclipse
  • That should work! Check the DDMS perspective for connected devices or use the adb devices command
0
source

All Articles