Android如何定位JNI错误行数

1.ndk-stack.cmd位置
   M:\Android\Sdk\ndk\21.1.6352462
2.aarch64-linux-android-addr2line.exe位置
   M:\Android\Sdk\ndk\21.1.6352462\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\bin

本文用的是arm64架构的,如果是其它架构,注意自己根据当前电脑环境将这两个位置加入到path环境变量中

1.用ndk-stack得到错误信息的具体内存地址
rem 注意,native的so库需要merged_native_libs目录里的而不是stripped_native_libs目录里的,stripped拿不到c++错误的具体位置的,得到的c++位置是?:??
adb logcat | ndk-stack -sym D:\ASProject\SurfaceWork\app\build\intermediates\merged_native_libs\debug\out\lib\arm64-v8a > ndkdump.txt
2.打开ndkdump.txt拿到出错的内存地址0x0000000000000a84, 注意报错地址后面一般是我们出错的.so文件(这一步其实应该可以直接拿到了我们cpp错误信息了,例如surfacework.cpp:46:41表示surfacework.cpp文件第46行41列这个位置,主要关注行数,列数可能会存在偏差)
********** Crash dump: **********
Build fingerprint: 'Redmi/apollo/apollo:11/RKQ1.200826.002/V12.5.8.0.RJDCNXM:user/release-keys'
#00 0x0000000000000a84 /data/app/~~gkxGnnnJG7dLnWViFImbuw==/com.bsktek.surfacework-FiltXQC4V82qAlgN23Wyjg==/lib/arm64/libsurfacework.so (Java_com_bsktek_surfacework_GLUtils_convertGLRGB888ToBitmap+376) (BuildId: f237091814578818a57a04ee4deba539aaaf4f96)
                                                                                                                                         Java_com_bsktek_surfacework_GLUtils_convertGLRGB888ToBitmap
                                                                                                                                         D:/ASProject/SurfaceWork/app/src/main/cpp\surfacework.cpp:46:41
#01 0x000000000013ced4 /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+148) (BuildId: d9d09da4285f1f09feadb805782797e4)
#02 0x00000000001337e8 /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+568) (BuildId: d9d09da4285f1f09feadb805782797e4)
#03 0x00000000001a8a94 /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+228) (BuildId: d9d09da4285f1f09feadb805782797e4)
#04 0x0000000000319390 /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+376) (BuildId: d9d09da4285f1f09feadb805782797e4)
#05 0x000000000030f6bc /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+996) (BuildId: d9d09da4285f1f09feadb805782797e4)
#06 0x00000000006802a4 /apex/com.android.art/lib64/libart.so (MterpInvokeStatic+548) (BuildId: d9d09da4285f1f09feadb805782797e4)
#07 0x000000000012d994 /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static+20) (BuildId: d9d09da4285f1f09feadb805782797e4)
#08 0x000000000002cf52 [anon:dalvik-classes2.dex extracted in memory from /data/app/~~gkxGnnnJG7dLnWViFImbuw==/com.bsktek.surfacework-FiltXQC4V82qAlgN23Wyjg==/base.apk!classes2.dex] (com.bsktek.surfacework.MainActivity$1.onDrawFrame+242)
#09 0x000000000067f024 /apex/com.android.art/lib64/libart.so (MterpInvokeInterface+1808) (BuildId: d9d09da4285f1f09feadb805782797e4)
#10 0x000000000012da14 /apex/com.android.art/lib64/libart.so (mterp_op_invoke_interface+20) (BuildId: d9d09da4285f1f09feadb805782797e4)
#11 0x00000000003712f4 /system/framework/framework.jar (offset 0x933000) (android.opengl.GLSurfaceView$GLThread.guardedRun+1112)
#12 0x000000000067fc68 /apex/com.android.art/lib64/libart.so (MterpInvokeDirect+1248) (BuildId: d9d09da4285f1f09feadb805782797e4)
#13 0x000000000012d914 /apex/com.android.art/lib64/libart.so (mterp_op_invoke_direct+20) (BuildId: d9d09da4285f1f09feadb805782797e4)
#14 0x00000000003718ec /system/framework/framework.jar (offset 0x933000) (android.opengl.GLSurfaceView$GLThread.run+48)
#15 0x0000000000306cb8 /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.11487796752256266877)+268) (BuildId: d9d09da4285f1f09feadb805782797e4)
#16 0x000000000066c054 /apex/com.android.art/lib64/libart.so (artQuickToInterpreterBridge+780) (BuildId: d9d09da4285f1f09feadb805782797e4)
#17 0x000000000013cff8 /apex/com.android.art/lib64/libart.so (art_quick_to_interpreter_bridge+88) (BuildId: d9d09da4285f1f09feadb805782797e4)
#18 0x0000000000133564 /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: d9d09da4285f1f09feadb805782797e4)
#19 0x00000000001a8a78 /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200) (BuildId: d9d09da4285f1f09feadb805782797e4)
#20 0x0000000000555ac4 /apex/com.android.art/lib64/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, jvalue const*)+460) (BuildId: d9d09da4285f1f09feadb805782797e4)
#21 0x00000000005a4e60 /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallback(void*)+1308) (BuildId: d9d09da4285f1f09feadb805782797e4)
#22 0x00000000000eb868 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+64) (BuildId: a790cdbd8e44ea8a90802da343cb82ce)
#23 0x000000000008ba88 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: a790cdbd8e44ea8a90802da343cb82ce)
Crash dump is completed
3.使用addr2line拿到出错的cpp文件信息和具体的行数
aarch64-linux-android-addr2line -f -C -e D:\ASProject\SurfaceWork\app\build\intermediates\merged_native_libs\debug\out\lib\arm64-v8a\libsurfacework.so 0x0000000000000a84

你可能感兴趣的:(Android如何定位JNI错误行数)