ndk-stack
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ndk-stack
ツールを使用すると、adb logcat
からのスタック トレースや、/data/tombstones/
の Tombstone をわかりやすく表示できます。このツールによって共有ライブラリ内部のすべてのアドレスがソースコードの対応する <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 Console では、ndk-stack
を使用してネイティブ アプリのスタック トレースをシンボル化しています。製品版のアプリでこの機能を有効にする方法については、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."]]