NK-STack
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เครื่องมือ ndk-stack
ช่วยให้คุณแสดงสแต็กเทรซจาก adb logcat
หรือไฟล์บันทึกข้อผิดพลาดใน /data/tombstones/
ได้ ซึ่งจะแทนที่ที่อยู่ภายในไลบรารีที่ใช้ร่วมกันด้วย<source-file>:<line-number>
ที่เกี่ยวข้องจากซอร์สโค้ดของคุณ ซึ่งจะช่วยให้การแก้ไขข้อบกพร่องง่ายขึ้น
เช่น แปลเป็นข้อความประมาณว่า
I/DEBUG ( 31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG ( 31): Build fingerprint: 'generic/google_sdk/generic/:2.2/FRF91/43546:eng/test-keys'
I/DEBUG ( 31): pid: 351, tid: 351 >>> /data/local/ndk-tests/crasher <<<
I/DEBUG ( 31): signal 11 (SIGSEGV), fault addr 0d9f00d8
I/DEBUG ( 31): r0 0000af88 r1 0000a008 r2 baadf00d r3 0d9f00d8
I/DEBUG ( 31): r4 00000004 r5 0000a008 r6 0000af88 r7 00013c44
I/DEBUG ( 31): r8 00000000 r9 00000000 10 00000000 fp 00000000
I/DEBUG ( 31): ip 0000959c sp be956cc8 lr 00008403 pc 0000841e cpsr 60000030
I/DEBUG ( 31): #00 pc 0000841e /data/local/ndk-tests/crasher
I/DEBUG ( 31): #01 pc 000083fe /data/local/ndk-tests/crasher
I/DEBUG ( 31): #02 pc 000083f6 /data/local/ndk-tests/crasher
I/DEBUG ( 31): #03 pc 000191ac /system/lib/libc.so
I/DEBUG ( 31): #04 pc 000083ea /data/local/ndk-tests/crasher
I/DEBUG ( 31): #05 pc 00008458 /data/local/ndk-tests/crasher
I/DEBUG ( 31): #06 pc 0000d362 /system/lib/libc.so
I/DEBUG ( 31):
ให้เป็นรูปแบบที่อ่านง่ายขึ้น
********** Crash dump: **********
Build fingerprint: 'generic/google_sdk/generic/:2.2/FRF91/43546:eng/test-keys'
pid: 351, tid: 351 >>> /data/local/ndk-tests/crasher <<<
signal 11 (SIGSEGV), fault addr 0d9f00d8
Stack frame #00 pc 0000841e /data/local/ndk-tests/crasher : Routine zoo in /tmp/foo/crasher/jni/zoo.c:13
Stack frame #01 pc 000083fe /data/local/ndk-tests/crasher : Routine bar in /tmp/foo/crasher/jni/bar.c:5
Stack frame #02 pc 000083f6 /data/local/ndk-tests/crasher : Routine my_comparison in /tmp/foo/crasher/jni/foo.c:9
Stack frame #03 pc 000191ac /system/lib/libc.so
Stack frame #04 pc 000083ea /data/local/ndk-tests/crasher : Routine foo in /tmp/foo/crasher/jni/foo.c:14
Stack frame #05 pc 00008458 /data/local/ndk-tests/crasher : Routine main in /tmp/foo/crasher/jni/main.c:19
Stack frame #06 pc 0000d362 /system/lib/libc.so
การใช้งาน
หากต้องการใช้ ndk-stack
ก่อนอื่นคุณต้องมีไดเรกทอรีที่มีไลบรารีที่ใช้ร่วมกันของแอปเวอร์ชันที่ไม่มีการลบข้อมูล หากคุณใช้ ndk-build
ไลบรารีที่แชร์ร่วมกันเหล่านี้จะอยู่ใน $PROJECT_PATH/obj/local/<abi>
โดยที่ <abi>
คือ ABI ของอุปกรณ์
สำหรับบิลด์ปลั๊กอิน Android Gradle (AGP) ไลบรารีที่ไม่ได้ลบข้อมูลบางส่วนออกจะอยู่ในที่เก็บข้อมูล <project-path>/build/intermediates/cxx/<build-type>/<hash>/obj/<abi>
โดยที่ <project-path>
คือไดเรกทอรีของโปรเจ็กต์ AGP ที่มีโมดูลที่คุณพยายามจะสัญลักษณ์ (โดยค่าเริ่มต้นคือ app
) <build-type>
คือชื่อประเภทบิลด์ CMake หรือ ndk-build (เช่น RelWithDebInfo
, Release
, Debug
ฯลฯ) <hash>
กำหนดเองได้ และ <abi>
คือ ABI ของอุปกรณ์
เครื่องมือนี้ใช้งานได้ 2 วิธี คุณสามารถป้อนข้อความ logcat เป็นอินพุตโดยตรงไปยังโปรแกรมได้
เช่น
adb logcat | $NDK/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi-v7a
นอกจากนี้ คุณยังใช้ตัวเลือก -dump
เพื่อระบุ logcat เป็นไฟล์อินพุตได้ด้วย เช่น
adb logcat > /tmp/foo.txt
$NDK/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi-v7a -dump foo.txt
เมื่อเริ่มแยกวิเคราะห์เอาต์พุตของ Logcat เครื่องมือจะมองหาบรรทัดแรกของเครื่องหมายดอกจัน
เช่น
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
หมายเหตุ: เมื่อคัดลอก/วางร่องรอย อย่าลืมใส่บรรทัดนี้ด้วย ไม่เช่นนั้น ndk-stack
จะไม่ทํางานอย่างถูกต้อง
ข้อมูลเพิ่มเติม
Google Play ใช้ ndk-stack
เป็นสัญลักษณ์ของสแต็กเทรซสำหรับแอปที่มาพร้อมเครื่องใน Google Play Console ดูข้อมูลเกี่ยวกับวิธีเปิดใช้การตั้งค่านี้สำหรับแอปในสภาพแวดล้อมเวอร์ชันที่ใช้งานจริงได้จากวิธีรวมไฟล์สัญลักษณ์การแก้ไขข้อบกพร่องของระบบสำหรับแอปใน Google Play Console
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","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 UTC"],[],[],null,["# ndk-stack\n\nThe `ndk-stack` tool allows you to symbolize stack traces from\n[`adb logcat`](/tools/help/logcat) or a\ntombstone in `/data/tombstones/`. It replaces any\naddress inside a shared library with the corresponding\n`\u003csource-file\u003e:\u003cline-number\u003e` from your source code,\nmaking debugging easier.\n\nFor example, it translates something like: \n\n```\nI/DEBUG ( 31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\nI/DEBUG ( 31): Build fingerprint: 'generic/google_sdk/generic/:2.2/FRF91/43546:eng/test-keys'\nI/DEBUG ( 31): pid: 351, tid: 351 \u003e\u003e\u003e /data/local/ndk-tests/crasher \u003c\u003c\u003c\nI/DEBUG ( 31): signal 11 (SIGSEGV), fault addr 0d9f00d8\nI/DEBUG ( 31): r0 0000af88 r1 0000a008 r2 baadf00d r3 0d9f00d8\nI/DEBUG ( 31): r4 00000004 r5 0000a008 r6 0000af88 r7 00013c44\nI/DEBUG ( 31): r8 00000000 r9 00000000 10 00000000 fp 00000000\nI/DEBUG ( 31): ip 0000959c sp be956cc8 lr 00008403 pc 0000841e cpsr 60000030\nI/DEBUG ( 31): #00 pc 0000841e /data/local/ndk-tests/crasher\nI/DEBUG ( 31): #01 pc 000083fe /data/local/ndk-tests/crasher\nI/DEBUG ( 31): #02 pc 000083f6 /data/local/ndk-tests/crasher\nI/DEBUG ( 31): #03 pc 000191ac /system/lib/libc.so\nI/DEBUG ( 31): #04 pc 000083ea /data/local/ndk-tests/crasher\nI/DEBUG ( 31): #05 pc 00008458 /data/local/ndk-tests/crasher\nI/DEBUG ( 31): #06 pc 0000d362 /system/lib/libc.so\nI/DEBUG ( 31):\n```\n\ninto the more readable: \n\n```\n********** Crash dump: **********\nBuild fingerprint: 'generic/google_sdk/generic/:2.2/FRF91/43546:eng/test-keys'\npid: 351, tid: 351 \u003e\u003e\u003e /data/local/ndk-tests/crasher \u003c\u003c\u003c\nsignal 11 (SIGSEGV), fault addr 0d9f00d8\nStack frame #00 pc 0000841e /data/local/ndk-tests/crasher : Routine zoo in /tmp/foo/crasher/jni/zoo.c:13\nStack frame #01 pc 000083fe /data/local/ndk-tests/crasher : Routine bar in /tmp/foo/crasher/jni/bar.c:5\nStack frame #02 pc 000083f6 /data/local/ndk-tests/crasher : Routine my_comparison in /tmp/foo/crasher/jni/foo.c:9\nStack frame #03 pc 000191ac /system/lib/libc.so\nStack frame #04 pc 000083ea /data/local/ndk-tests/crasher : Routine foo in /tmp/foo/crasher/jni/foo.c:14\nStack frame #05 pc 00008458 /data/local/ndk-tests/crasher : Routine main in /tmp/foo/crasher/jni/main.c:19\nStack frame #06 pc 0000d362 /system/lib/libc.so\n```\n\nUsage\n-----\n\nTo use `ndk-stack`, you first need a directory containing unstripped versions of\nyour app's shared libraries. If you use `ndk-build`, these unstripped shared\nlibraries are found in `$PROJECT_PATH/obj/local/\u003cabi\u003e`, where `\u003cabi\u003e` is your\ndevice's ABI.\n\nFor an Android Gradle Plugin (AGP) build, the unstripped libraries will be in\n`\u003cproject-path\u003e/build/intermediates/cxx/\u003cbuild-type\u003e/\u003chash\u003e/obj/\u003cabi\u003e`, where\n`\u003cproject-path\u003e` is the directory of the AGP project that contains the module\nyou're trying to symbolize (by default this is `app`), `\u003cbuild-type\u003e` is the\nname of the CMake or ndk-build build type (such as `RelWithDebInfo`, `Release`,\n`Debug`, etc.), `\u003chash\u003e` is arbitrary, and `\u003cabi\u003e` is your device's ABI.\n\nThere are two ways to use the tool. You can feed the logcat text as direct input to the program.\nFor example: \n\n```\nadb logcat | $NDK/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi-v7a\n```\n\nYou can also use the `-dump` option to specify the logcat as an input file. For example: \n\n```\nadb logcat \u003e /tmp/foo.txt\n$NDK/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi-v7a -dump foo.txt\n```\n\nWhen it begins parsing the logcat output, the tool looks for an initial line of asterisks.\nFor example: \n\n```\n*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n```\n\n**Note:** When copy/pasting traces, don't forget this line, or\n`ndk-stack` won't work correctly.\n\nMore information\n----------------\n\nGoogle Play uses `ndk-stack` to symbolize stack traces for native\napps in the Google Play Console. For information on how to enable this for your\napp in a production environment, see how to\n[include a native debug symbols file](/studio/build/shrink-code#strip-native-libraries)\nfor your app in the Google Play Console."]]