Search code examples
androidandroid-emulatoradb

Disconnect network in Android emulator while keeping ADB alive


I have made a mistake somewhere in my code that my Android app crashes when I switch off the network in the emulator while the app's HTTPClient is making some request.

But I cannot debug it, because when I switched off the network, I also lost the ADB connection. Thus I cannot see what exception is causing the crash.

I have tried switching off the network by:

  • F8
  • Set 'Data' to 'Unregistered' or 'Denied' in DDMS Emulator Control

I can put my Mac offline and ADB will stay up, but unfortunately I cannot reproduce the crash that way.

Is there a way to turn off network in the emulator, while keeping ADB alive? I basically need access to the LogCat entries.

Thanks!


Solution

  • You can run logcat from the device instead of from ADB and redirect it to a file for offline reading.

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

    Instead of

    adb logcat [-v threadtime]
    

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