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:
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!
You can disable the Internet connection by pressing F8 in any Android emulator. It is a toggle button, so if it doesn't have Internet connection then it will start the Internet connection and if it already has an Internet connection then it will dis-connect it.
Click Advanced -> Click on Tab DNS -> Click on Add. Write 8.8. 8.8 & Click Add, It will look like. Check your emulator, you should access internet.
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.
On linux this is pretty simple with iptables firewall. I suppose you trying to debug api calls so just block api host:
iptables -I OUTPUT -d api.example.com -j DROP
Sure you can do the same thing with Mac or Windows firewall.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With