Android Apk跑native层代码挂死,日志如下:
12-11 20:13:47.321 I/DEBUG ( 1491): backtrace:
12-11 20:13:47.321 I/DEBUG ( 1491): #00 pc 00100696 /data/app-lib/com.huawei.hmt.hmtCloudAlbum-1/libnative-FaceClustering.so
12-11 20:13:47.321 I/DEBUG ( 1491): #01 pc 00100a0f /data/app-lib/com.huawei.hmt.hmtCloudAlbum-1/libnative-FaceClustering.so (std::vector<float, std::allocator<float> >::_M_default_append(unsigned int)+138)
需要查看是哪一行代码的错误,本文先讲在AndroidStudio如何反编译找到错误代码行,linux下编译的情况待后续补充
步骤
(1)找到NDK反编译工具:
C:\Users\xxx\AppData\Local\Android\Sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-addr2line.exe
NDK目录可以从AndroidStudio工具Project Structure->SDK Location中找,如下:
(2)找到出问题的库的调试版本,在如下目录:
你的工程\app\build\intermediates\cmake\debug\obj\armeabi-v7a
(3)执行如下命令:
C:\Users\xxxx\AppData\Local\Android\Sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-addr2line.exe -e C:\Users\xxxx\Desktop\libnative-test.so 0x00100696
其中0x00100696为日志中打印的 00100696前面加上0x