android studio debug记录

本文涵盖Android开发中常见的E/ART:Failed sending reply to debugger: Broken pipe问题、A/libc:Fatal signal 11(SIGSEGV)异常、System.out.print使用技巧、Log级别详解、GSEGV(SEGV_MAPERR)异常解析及ndk-stack定位crash方法。提供详尽的解决方案和实用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

①E/ART: Failed sending reply to debugger: Broken pipe.

参考链接:https://stackoverflow.com/questions/31436157/e-art-failed-sending-reply-to-debugger-broken-pipe-but-application-still-runs

What is a broken pipe?

Your dev machine and the Android device communicate like a client server and a broken pipe means that the communication has become invalid. For instance, the client (the Android device) is trying to send a reply to the server (the adb process running on the dev machine) but the server has already closed the socket.

如何修复

First make sure your app is building correctly by performing a clean/rebuild.

Then if you are running your app using USB debugging on a real phone then you can often fix the problem by unplugging the USB cable and then plugging it back in to reestablish the client/server connection.

If this doesn’t work, you can disconnect the USB cable and (stop the emulator if necessary) and close Android Studio. This is often enough to stop the adb process. Then when you open Android Studio again it will restart and the connection will be reestablished.

If this doesn’t work, you can try stopping the adb server manually using the instructions in this question. For instance, you can try opening command prompt or terminal and going to the sdk/platform-tools directory and typing:

adb kill-server
adb start-server

② A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 15280 (pool-1-thread-1), pid 15203

参考链接:https://stackoverflow.com/questions/17840521/android-fatal-signal-11-sigsegv-at-0x636f7d89-code-1-how-can-it-be-tracked/33678476

③Android Studio查看System.out.print的内容

debug途中System.out.print着实好用吗,参考链接:https://blog.youkuaiyun.com/jessicababy1994/article/details/86544182

④Log.v,Log.d,Log.i,Log.w,Log.e

android.util.Log常用的方法有以下5个:

  1. Log.v 的调试颜色为黑色的,任何消息都会输出,这里的v代表verbose啰嗦的意思,平时使用就是Log.v("","");
  2. Log.d的输出颜色是蓝色的,仅输出debug调试的意思,但他会输出上层的信息,过滤起来可以通过DDMS的Logcat标签来选择.
  3. Log.i的输出为绿色,一般提示性的消息information,它不会输出Log.v和Log.d的信息,但会显示i、w和e的信息
  4. Log.w的意思为橙色,可以看作为warning警告,一般需要我们注意优化Android代码,同时选择它后还会输出Log.e的信息。5. Log.e为红色,可以想到error错误,这里仅显示红色的错误信息,这些错误就需要我们认真的分析,查看栈的信息了。

注意:不同的打印方法在使用时都是某个方法带上(String tag, String msg)参数,tag表示的是打印信息的标签,msg表示的是需要打印的信息。
Log.v("----------logv",“This is Verbose.”);
Log.d("----------logd",“This is Debug.”);
Log.i("----------logt",“This is Information”);
Log.w("----------logw",“This is Warnning.”);
Log.e("----------loge",“This is Error.”);

⑤Android bug之GSEGV(SEGV_MAPERR)异常及解决

segmentation fault, 段错误

一般由a dangling pointer issue, or some sort of buffer overflow有两种SEGV,由一次无效内存访问错误引起。

1,A page was accessed which had the wrong permissions. 如某块内存区域是只读的,而程序尝试去写该块内存。SEGV_ACCERR
2,A page was accessed that is not even mapped into the address space of the application at all.

⑥Android studio下使用ndk-stack定位crash

参考:https://blog.youkuaiyun.com/a568478312/article/details/78182422

### 查看 Android StudioDebug 包的日志方法 要在 Android Studio 中查看 Debug 包的日志,可以通过以下方式实现: #### 使用 Logcat 工具 Logcat 是 Android Studio 提供的一个强大的日志查看工具。它能够实时显示设备上的运行日志信息,帮助开发者定位问题并分析程序行为。 要打开 Logcat 面板,可以在 Android Studio 的底部找到对应的选项卡[^1]。如果未看到该选项卡,可以选择菜单栏中的 `View -> Tool Windows -> Logcat` 来手动开启。 在 Logcat 中设置过滤条件以便更高效地查找特定应用的日志。例如,通过输入包名或者指定标签来缩小范围。此外,还可以调整日志级别(Verbose, Debug, Info, Warn, Error, Assert),从而专注于不同类型的日志消息[^3]。 #### Attaching Debugger 到进程 当需要深入观察应用程序的行为时,除了简单的日志打印外,也可以利用调试功能进一步探索内部状态变化情况。对于已安装好的 debug 版本的应用来说,可以直接选择 “Attach Debugger to Android Process”,这会弹出一个可供附加的目标列表界面。从中挑选目标进程完成连接操作之后即可启动断点跟踪等功能[^2]。 需要注意的是,在执行上述步骤前应确保所使用的 APK 文件具有可被调试属性(即设置了 android:debuggable="true")。这样才能够正常启用这些高级特性支持完整的错误诊断流程。 ```java // 示例代码展示如何自定义日志输出 public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.d(TAG, "onCreate method called"); } } ``` 以上便是关于如何在 Android Studio 中有效监控以及解析来自 Debug 包产生的各类记录数据的方法介绍。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值