Unity Android Crash 简单定位

官方文档Symbolicate Android Crash

unity安卓项目有时候会出现安卓闪退,崩溃出来的堆栈类似如下

2020-01-13 15:40:47.554 12602-12739/xx.xx.xx.xx E/CRASH:

#00 pc 000000000000069c [vdso] () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#01 pc 000000000001ceb8 /system/lib64/libc.so (memset+136) 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#02 pc 0000000000a5abe4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#03 pc 0000000000a5ac00 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#04 pc 0000000000a5ac00 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#05 pc 0000000000a5ac00 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#06 pc 0000000000a5ac00 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#07 pc 0000000000a5ac00 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#08 pc 0000000000a5ac00 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#09 pc 0000000000a5ac00 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#10 pc 0000000000a5ac00 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#11 pc 0000000000a5ac00 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#12 pc 0000000000a5ac00 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#13 pc 0000000000a38fc4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#14 pc 0000000000a4ac54 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#15 pc 0000000000a4aaa8 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#16 pc 00000000004efae0 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libunity.so (_ZN11Marshalling17ArrayUnmarshallerINS_18StringArrayElementES1_E18ArrayFromContainerISt6vectorIN4core12basic_stringIcNS5_20Stri ngStorageDefaultIcEEEESaIS9_EELb1EE14UnmarshalArrayERKSB_+148) 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#17 pc 00000000004ef170 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libunity.so (_Z48AssetBundleManifest_CUSTOM_GetDirectDependenciesP12Il2CppObjectP12Il2CppString+244) 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#18 pc 0000000000f6a378 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#19 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#20 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#21 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#22 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#23 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#24 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#25 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#26 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#27 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#28 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#29 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#30 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so () 2020-01-13 15:40:47.555 12602-12739/xx.xx.xx.xx E/CRASH:

#31 pc 0000000000f6a3f4 /data/app/xx.xx.xx.xx-tcfkPS-N3WH5aQuqMs6lVA==/lib/arm64/libil2cpp.so ()

unity的符号表文件一般在导出安卓项目时生成的symbols.zip文件里。
可以通过使用addr2line工具将上面崩溃堆栈的内存地址转成具体的方法,addr2line在ndk的文件夹下找到(以mac版本r16b为例):
64位:android-ndk-r16b/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-addr2line
32位:android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-addr2line

例如

./aarch64-linux-android-addr2line -f -C -e   libil2cpp.sym 0000000000f6a378 0000000000f6a3f4

执行结果类似如下

BundleManager_LoadTask_mD57E35306E924ABDF527B9ABC7E4C1C412484CAA
...../StagingArea/Il2Cpp/il2cppOutput/Bulk_Assembly-CSharp_0.cpp:39598
BundleManager_LoadTask_mD57E35306E924ABDF527B9ABC7E4C1C412484CAA
..../StagingArea/Il2Cpp/il2cppOutput/Bulk_Assembly-CSharp_0.cpp:39653