繁体   English   中英

如何在不连接 PC 的情况下在设备中保存 android 运行时错误日志?

[英]How to save android runtime error logs in device without connected to PC?

我只是想问一下是否可以在没有设备连接到PC的情况下将android运行时错误信息保存在sdcard中? 我试着跑:
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_monkey.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 &"
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();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM