调试平台代码
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android Studio for Platform (ASfP) 提供了一个强大的调试程序,可让您执行以下操作:
- 选择要调试的设备。
- 在 Java、Kotlin 和 C/C++ 代码中设置断点。
- 在运行时检查变量和对表达式求值。
在使用调试器之前,您必须将 build 刷写到设备或模拟器。
应用进程 (Java/Kotlin) 调试
如需调试 Java 或 Kotlin 应用进程,请执行以下操作:
在 ASfP 中设置 Java 或 Kotlin 代码中的断点。
从菜单中依次选择 Run > Attach Debugger to Android Process。
在 Choose Process 对话框中,确保将调试类型设置为 Java Only。
从列表中选择您的设备。
选择要调试的特定应用进程。
点击确定。
与设备上的应用互动,以触发断点。
系统进程 (C/C++) 调试
如需调试使用 C 或 C++ 编写的系统进程,请执行以下操作:
验证您是否只运行了一个设备或模拟器。
打开终端,然后从 AOSP 代码库根目录运行 adb root
:bash
adb root
在 ASfP 中设置 C/C++ 代码断点。
从菜单中依次选择 Run > Attach Debugger to Android Process。
在 Choose Process 对话框中,将调试类型更改为 Native Only 或 Dual (Java + Native)。
勾选 Show all processes 复选框即可查看系统进程。
从列表中选择您的设备。
选择要调试的特定系统进程(例如 surfaceflinger
或 system_server
)。
点击确定。
调试程序会附加到该进程。与设备互动以命中您的断点。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-04。
[null,null,["最后更新时间 (UTC):2025-09-04。"],[],[],null,["Android Studio for Platform (ASfP) provides a powerful debugger that lets you:\n\n- Select a device to debug on.\n- Set breakpoints in your Java, Kotlin, and C/C++ code.\n- Examine variables and evaluate expressions at runtime.\n\nBefore you use the debugger, you must flash your build to a device or emulator.\n\nApp process (Java/Kotlin) debugging\n\nTo debug a Java or Kotlin application process:\n\n1. Set breakpoints in your Java or Kotlin code within ASfP.\n\n2. Select **Run \\\u003e Attach Debugger to Android Process** from the menu.\n\n3. In the **Choose Process** dialog, make sure the **Debug type** is set to\n **Java Only**.\n\n4. Select your device from the list.\n\n5. Choose the specific application process you want to debug.\n\n6. Click **OK**.\n\n7. Interact with the application on your device to hit the breakpoints.\n\nSystem process (C/C++) debugging\n\nTo debug a system process written in C or C++:\n\n1. Verify that you have only one device or emulator running.\n\n2. Open a terminal and run `adb root` from your AOSP checkout root: `bash\n adb root`\n\n\u003c!-- --\u003e\n\n1. Set breakpoints in your C/C++ code within ASfP.\n\n2. Select **Run \\\u003e Attach Debugger to Android Process** from the menu.\n\n3. In the **Choose Process** dialog, change the **Debug type** to **Native\n Only** or **Dual (Java + Native)**.\n\n4. Check the **Show all processes** box to see system processes.\n\n5. Select your device from the list.\n\n6. Choose the specific system process you want to debug (such as\n `surfaceflinger` or `system_server`).\n\n7. Click **OK**.\n\n8. The debugger attaches to the process. Interact with the device to hit your\n breakpoints."]]