偵錯平台代碼
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android Studio for Platform (ASfP) 提供強大的偵錯工具,可讓您執行下列操作:
- 選取要偵錯的裝置。
- 設定 Java、Kotlin 和 C/C++ 程式碼的中斷點。
- 在執行階段檢查變數及評估運算式。
使用偵錯工具前,請務必將建構版本刷入裝置或模擬器。
應用程式程序 (Java/Kotlin) 偵錯
如要對 Java 或 Kotlin 應用程式程序進行偵錯,請按照下列步驟操作:
在 ASfP 的 Java 或 Kotlin 程式碼中設定中斷點。
在選單中依序選取「Run」>「Attach Debugger to Android Process」。
在「Choose Process」對話方塊中,確認「Debug type」已設為「Java Only」。
從清單中選取裝置。
選擇要偵錯的特定應用程式程序。
按一下「OK」。
與裝置上的應用程式互動,觸發中斷點。
系統程序 (C/C++) 偵錯
如要對以 C 或 C++ 編寫的系統程序進行偵錯,請按照下列步驟操作:
確認您只執行一部裝置或模擬器。
開啟終端機,然後從 AOSP 結帳根目錄執行 adb root
:bash
adb root
在 ASfP 中設定 C/C++ 程式碼的中斷點。
在選單中依序選取「Run」>「Attach Debugger to Android Process」。
在「Choose Process」對話方塊中,將「Debug type」變更為「Native Only」或「Dual (Java + Native)」。
勾選「顯示所有程序」方塊,即可查看系統程序。
從清單中選取裝置。
選擇要偵錯的特定系統程序 (例如 surfaceflinger
或 system_server
)。
按一下「OK」。
偵錯工具會附加至程序。與裝置互動,達到中斷點。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-09-04 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間: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."]]