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

标签 android runtime-error adb logcat

我只想问一下,在没有连接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();
}

关于android - 如何在未连接到 PC 的情况下在设备中保存 android 运行时错误日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22633217/

相关文章:

android - 无法为 googleplay 版本集成 admob 插页式广告

java - 将java按钮添加到LinearLayout

android - 从 Android 模拟器访问本地 VirtualBox 上的 Node.js

runtime-error - Ren-C 错误 :; "word is bound relative to context not on stack"

android-studio - Windows 10 中的 adb.exe 位于哪里?

android - ADB over TCP - 设备已连接并在线但安装显示错误 : Device not found

android - 屏幕旋转时的 ViewModel 更新

android - 如何解决这些错误 : acAppName=/system/bin/surfaceflinger and org. json.JSONObject cannot be converted to JSONArray?

java.security.AccessControlException : access denied (java. lang.RuntimePermission accessClassInPackage.sun.security.pkcs11)

android - 更改运行 adb 服务器的默认端口(即 5037)