[[["容易理解","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-07-27 (世界標準時間)。"],[],[],null,["# Debug pre-built APKs\n\nAndroid Studio 3.0 and higher lets you profile and debug APKs that have\n[debugging enabled](/studio/debug#enable-debug) without having\nto build them from an Android Studio project.\n\nTo start debugging an APK, follow these steps:\n\n1. From the Android Studio Welcome screen, click **Profile or debug APK**.\n\n If you already have a project open, click\n **File \\\u003e Profile or Debug APK** from the menu bar.\n2. In the dialog that opens,\n select the APK you want to import into Android Studio.\n\n3. Click **OK**.\n\nIf this option does not show up, make sure you have the \"Android APK Support\" plugin enabled.\n\nAndroid Studio then displays the unpacked APK files, similar to figure 1.\nThis is not a fully decompiled set of files, but it does provide SMALI\nfiles for a more readable version of the DEX files.\n\n**Figure 1.** Importing a pre-built APK into Android\nStudio.\n| **Note:** When you import an APK into Android Studio, the IDE creates a new project in your home directory under `ApkProjects/` and makes a local copy of the target APK there. The SMALI files are stored in the `smali/out/` folder within the new project folder.\n\nThe **Android** view in the Project pane lets you inspect the following\ncontents of your APK:\n\n- **APK file:** Double-click the APK to open the APK analyzer.\n- **manifests:** Contains the app manifests that are extracted from the APK.\n- **java:** Contains Kotlin or Java code that Android Studio disassembles (into SMALI files) from your APK's DEX files. Each SMALI file in this directory corresponds to a Kotlin or Java class.\n- **cpp:** If your app includes native code, this directory contains your APK's native libraries (SO files).\n- **External Libraries:** Contains the Android SDK.\n\nYou can\n[use the Android profiler](/studio/profile/android-profiler) to start\ntesting your app's performance.\n\nTo debug your app's Kotlin or Java code, you need to\n[attach the Kotlin or Java sources](#attach_java) and add breakpoints in the\nKotlin or Java source files. Similarly, to debug your native code, you must\n[attach the native debug symbols](#attach_native).\n\nAttach Kotlin or Java sources\n-----------------------------\n\nBy default, Android Studio extracts Kotlin or Java code from your APK and\nsaves it as SMALI files. To debug the Kotlin or Java code using\nbreakpoints, you need to point the IDE to the Kotlin or Java source files\nthat correspond to the SMALI files you want to debug.\n\nTo attach Kotlin or Java sources, proceed as follows:\n\n1. Double click on a SMALI file from the **Project** pane in the **Android** view. After opening the file, the editor displays a banner asking you to select the Kotlin or Java sources:\n2. Click **Attach Kotlin/Java Sources...** from the banner in the editor window.\n3. Navigate to the directory with the app's Kotlin or Java source files and click **Open**.\n\nIn the **Project** window, Android Studio replaces SMALI files with their\ncorresponding Kotlin or Java source files. Android Studio also includes inner\nclasses automatically. You can now add breakpoints and\n[debug your app](/studio/debug).\n\nAttach native debug symbols\n---------------------------\n\nIf your APK includes native libraries (SO files) that don't include debug\nsymbols, Android Studio shows you a banner, similar to\nthe one shown in figure 1. You can't debug the APK's native code or use\nbreakpoints without attaching debuggable native libraries.\n\nTo attach debuggable native libraries, proceed as follows:\n\n1. If you haven't already done so, [download the NDK and tools](/ndk/guides#download-ndk).\n2. In **Android** view, under the **cpp** directory in\n the **Project** window, double-click a native\n library file that doesn't include debug symbols.\n\n The editor shows a\n table of all the ABIs your APK supports.\n3. Click **Add** in the top-right corner of the editor window.\n\n4. Navigate to the directory that includes the debuggable native libraries\n you want to attach and click **OK**.\n\nIf the APK and debuggable native libraries were built using a different\nworkstation, you need to also specify paths to the local debug symbols by\nfollowing these steps:\n\n1. Add local paths to missing debug symbols by editing the field under the\n **Local Paths** column in the **Path Mappings** section of the editor\n window, shown in figure 2.\n\n In most cases, you need only provide the\n path to a root folder, and Android Studio automatically inspects\n subdirectories to map additional sources. Android Studio also\n automatically maps paths to a remote NDK to your local NDK download.\n2. Click **Apply Changes** in the **Path Mappings** section of the editor\n window.\n\n\n**Figure 2.** Local paths to debug\nsymbols.\n\n\u003cbr /\u003e\n\nThe native source files appear in the **Project** window. Open\nthose native source files to add breakpoints and\n[debug your app](/studio/debug). To\nremove the mappings, click **Clear** in the **Path Mappings** section of\nthe editor window.\n\n\n**Known issue:** When attaching debug symbols to an APK, both the APK and\ndebuggable SO files must be built using the same workstation\nor build server.\n\nIn Android Studio 3.6 and higher, you don't need to create a new project\nwhen the APK is updated outside the IDE. Android Studio detects changes in\nthe APK and gives you the option to re-import it.\n\n**Figure 3.** APKs updated\noutside Android Studio can be re-imported.\n\n\u003cbr /\u003e"]]