[Mac] How to Analyze Native Crashes on Android

0. System environment
Mac OSX 10.11.6
Eclipse for Android 4.6.0
Android SDK v21
Android NDK r12d

1. Environment setup
This guide assumes you already have the Android SDK and NDK installed in ANDROID_SDK_PATH and ANDROID_NDK_PATH, respectively.

1) Install ADB (skip to the next step if it is already installed):
Check whether ADB is installed. If not, open Window -> Android SDK Manager and install Android SDK Tools and Android Platform Tools:
41CAB727-ACA5-480E-8EDB-2BC18BF8DA67

2) Configure ADB:
Run the following at the command line:

echo 'export PATH=$PATH:ANDROID_SDK_PATH/platform-tools/' >> ~/.bash_profile

Replace ANDROID_SDK_PATH with the actual path to your Android SDK installation.

Run the following command to test the installation:

adb devices

If you see output like this:

List of devices attached
04157df41c14bf29	device

then ADB is configured correctly.

3) Configure ndk-stack:
Run the following at the command line:

echo 'export PATH=$PATH:ANDROID_NDK_PATH/' >> ~/.bash_profile

Replace ANDROID_NDK_PATH with the actual path to your Android NDK installation.

2. Steps
1) When a crash occurs, use ADB to save the crash log:

adb logcat > ANDROID_CRASHLOG_PATH/logs.txt

ANDROID_CRASHLOG_PATH is the path where you want to save the crash log.

2) Run ndk-stack to analyze the log:

ndk-stack -sym ANDROID_PROJECT_PATH/libs/armeabi-v7a/ -dump ANDROID_CRASHLOG_PATH/log.txt

ANDROID_PROJECT_PATH is your Android project directory. Your native libraries are typically stored in a directory such as ANDROID_PROJECT_PATH/libs/armeabi-v7a/ or armabi. Pass the path to that directory as the first argument.

If ndk-stack cannot pinpoint where the crash occurred, for example because the symbol table was not retained, use a path such as obj/local/armeabi-v7a in the project where you built your native libraries instead.

If everything runs correctly, you’ll see a crash log like this:

********** Crash dump: **********
Build fingerprint: 'samsung/zeroltezc/zeroltechn:6.0.1/MMB29K/G9250ZCS2DPH2:user/release-keys'
pid: 31387, tid: 31428, name: Binder_3  >>> com.tencent.qarsdk <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x626f2075
Stack frame #00 pc 001d08b4  /system/lib/libart.so (_ZN3art2gc5space19LargeObjectMapSpace5AllocEPNS_6ThreadEjPjS5_S5_+151)
Stack frame #01 pc 0012bdb7  /system/lib/libart.so (_ZN3art2gc4Heap16AllocLargeObjectILb1ENS_6mirror16SetLengthVisitorEEEPNS3_6ObjectEPNS_6ThreadEPPNS3_5ClassEjRKT0_+130)
Stack frame #02 pc 002a2d3b  /system/lib/libart.so (_ZN3art6mirror14PrimitiveArrayIaE5AllocEPNS_6ThreadEj+498)
Stack frame #03 pc 002a39fb  /system/lib/libart.so (_ZN3art3JNI12NewByteArrayEP7_JNIEnvi+322)
Stack frame #04 pc 0010c6cb  /system/lib/libart.so (_ZN3art8CheckJNI17NewPrimitiveArrayEPKcP7_JNIEnviNS_9Primitive4TypeE+586)
Stack frame #05 pc 000a64c7  /system/lib/libandroid_runtime.so (_ZN16JNICameraContext11copyAndPostEP7_JNIEnvRKN7android2spINS2_7IMemoryEEEi+138)
Stack frame #06 pc 000a68f3  /system/lib/libandroid_runtime.so (_ZN16JNICameraContext8postDataEiRKN7android2spINS0_7IMemoryEEEP21camera_frame_metadata+102)
Stack frame #07 pc 00021f5d  /system/lib/libcamera_client.so (_ZN7android6Camera12dataCallbackEiRKNS_2spINS_7IMemoryEEEP21camera_frame_metadata+58)
Stack frame #08 pc 00026d79  /system/lib/libcamera_client.so (_ZN7android14BnCameraClient10onTransactEjRKNS_6ParcelEPS1_j+190)
Stack frame #09 pc 000199c9  /system/lib/libbinder.so (_ZN7android7BBinder8transactEjRKNS_6ParcelEPS1_j+60)
Stack frame #10 pc 0001ed5d  /system/lib/libbinder.so (_ZN7android14IPCThreadState14executeCommandEi+552)
Stack frame #11 pc 0001eee9  /system/lib/libbinder.so (_ZN7android14IPCThreadState20getAndExecuteCommandEv+64)
Stack frame #12 pc 0001ef4d  /system/lib/libbinder.so (_ZN7android14IPCThreadState14joinThreadPoolEb+48)
Stack frame #13 pc 000239fd  /system/lib/libbinder.so
Stack frame #14 pc 000101fd  /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+112)
Stack frame #15 pc 00062d93  /system/lib/libandroid_runtime.so (_ZN7android14AndroidRuntime15javaThreadShellEPv+70)
Stack frame #16 pc 0003fc63  /system/lib/libc.so (_ZL15__pthread_startPv+30)
Stack frame #17 pc 0001a39b  /system/lib/libc.so (__start_thread+6)

Now you can use the log to figure out what caused the crash!

Common issues:
1) Can’t find Android SDK Manager:
Solution: Go to Window -> Perspective -> Open Perspective and select Java. You should then be able to find Android SDK Manager.

Add a Comment

Your email address will not be published. Required fields are marked *