我只是想问一下,如果没有设备连接到PC,是否可以在sdcard中保存android运行时错误信息?我试着跑:
adb shell "logcat -v threadtime *:V > /mnt/sdcard/logcat_log.txt"
当我插入USB时缺少运行时错误。
有什么想法?感谢您的评论。
我刚刚挖掘了一些信息。从一开始,我就把这个命令'adb shell“logcat -v threadtime -f /mnt/sdcard/logcat_log.txt”'将日志输出到'logcat_log.txt'文件中。经过几次测试,检查和记录有关logcat的文档,我发现这个命令只会刷新android的日志缓冲区然后 STOP 。这就是为什么我不能在没有再次刷新日志缓冲区的情况下在此文件中获取运行时错误信息的原因。感谢Pragna和Narkha的回复。
我只是把我的解决方案放在这里,以便将来可能需要它。我的测试平台是Windows 7,如果你使用Linux或Mac OS X会更好,并且解决方案包含用于windows的bat脚本,用于android shell的shell脚本;它们是run.bat,logcat.sh,run_monkey.sh和run_logcat.sh。
#"run.bat"
adb shell "echo "" > /mnt/sdcard/logcat_log.txt" #clean up previous log
adb push logcat.sh /mnt/sdcard/ #
start bash run_logcat.sh
start bash run_monkey.sh
pause
#"logcat.sh"
logcat -v threadtime *:V > /mnt/sdcard/logcat_log.txt
#"run_moneky.sh"
adb shell "monkey -p com.test.androidclient --throttle 300 -c android.intent.category.MONKEY -c android.intent.category.LAUNCHER -c android.intent.category.DEFAULT --pct-majornav 20 --monitor-native-crashes --ignore-security-exceptions --ignore-crashes --ignore-timeouts --kill-process-after-error -s 220 -v -v -v 99999"
#"run_logcat.sh"
adb shell "sh /mnt/sdcard/logcat.sh &"
答案 0 :(得分:2)
try {
File logfile= new File(Environment.getExternalStorageDirectory()+"/logfile.log");
filename.createNewFile();
String cmd = "logcat -d -f "+logfile.getAbsolutePath();
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}