Search code examples
androidadtlogcat

redirect adb logcat to android avd


i want to redirect the Android developer tools logcat output to a file into the virtual device from a shell command, before than running the android app test. The command i usually use to redirect the output to a file is:

adb shell logcat -v time - f log.txt packageName:F *:E > /folder/log.txt

but it puts the log file into a computer directory (/folder/ in this case). I want to change it with a directory in the virtual device but like above, it says the folder does not exist. There is way to do it via shell command?


Solution

  • You can simply do

    adb shell "logcat -v time -f /mnt/sdcard/log.txt packageName:F *:E"
    

    to accomplish it all in one command from the host shell. You do not need the redirect when you use the -f flag, in fact the redirect would not capture anything if you have directed the output of logcat to a file rather than to stdout.

    If that is not working, it is either because you are using a version of Android which mounts the external storage at some other path, or you do not have an emulated sdcard attached to your virtual device.

    You can investigate either of these problems by examining the output of

    adb shell mount
    

    If you do not have an sdcard at all on your AVD, follow the emulator documentation instructions for creating and attaching one.

    For testing purposes only there may be other paths than the sdcard at which you can write, particularly on an emulator where the adb shell runs as root, for example on some versions /data/local or similar.