Android logcat: Unexpected EOF! 解决办法

发布时间 2023-05-09 15:08:33作者: CuriousZero

 

【问题表现】

无论使用控制台adb( adb logcat | grep "SilentPlayerManager")还是使用Android Studio的logcat,都提示:

 

logcat: Unexpected EOF!

This means that either the device shut down, logd crashed, or this instance of logcat was unable to read log
messages as quickly as they were being produced.

If you have enabled significant logging, look into using the -G option to increase log buffer sizes.

 
 

【问题原因】

通过错误日志来看,问题很明显是logcat的日志缓冲区给刷爆了导致的
 
查看logcat日志缓冲区大小:adb logcat -g 

 发现只有256KB,可能有点小了。

所以当我们在调试时,产生的日志过多,就很容出现日志缓冲区被刷爆的问题了。
 

【解决办法】

方法一:可以通过logcat -G 来临时设置缓冲区的大小

比如:adb logcat -G 5M

 可以看到,设置缓冲区成功。此时需要通过logcat进行调试的时候,就不会出现缓冲区拉爆的情况了。

 

方法二:通过手机客户端设置

从Android 5.0开始,在开发者选项中,可以通过显示/允许增加环形缓冲区的大小,进行相关的缓冲区的大小设置,如下所示:

 

选择大小:

 

 

 

检查一下,设置成功了:

 

日志可以正常展示了: