开发

使用 Android Studio 进行原生调试

本节介绍如何在 Android Studio 中调试示例原生应用。
在项目导入期间创建的默认配置只支持 Java 调试。
在 Android Studio 工具栏的配置下拉菜单中,选择编辑配置…
Android Studio toolbar with the Configurations dropdown menu open.
如下所示,新建 Android 应用配置:
Run/Debug Configurations dialog with the add new Android App configuration option.
运行/调试配置对话框的通用选项卡中,为配置命名并选择一个模块。
General tab of Run/Debug Configuration dialog with name and module fields.
运行/调试配置对话框的调试器选项卡中,将调试类型更改为原生,然后添加符号路径:
Debugger tab set to Native debug type with symbol search path fields.
请注意,ndk-build 将删除的库放在 libs/ 目录中。必须将符号搜索路径指向 obj/local/<arch> 目录。这也不是递归搜索路径,因此必须将完整路径设置为 obj/local/armeabi-v7a 目录。
Symbol path pointing to the obj/local/armeabi-v7a directory for unstripped libraries.

疑难解答

如果您在 AInputQueue_preDispatchEvent 遇到 SIGILL (illegal instruction) 应用程序崩溃,可以通过禁用 LLDB 中的 SIGILL 处理程序来解决。请按照以下说明进行操作:
  1. 在 Android Studio 中打开应用程序。
  2. 打开运行 > 编辑配置
  3. 运行/调试配置窗口中,务必在左窗格中选择您的应用,然后点击右窗格中的调试器选项卡。
  4. 调试器选项卡,点击下方的 LLDB Post Attach Commands 选项卡。
  5. 点击右侧的 +,添加以下命令,然后按 Enter 键:
    process handle --pass true --stop false --notify true SIGILL
    
  6. 点击确定,应用更改。