如何避免剥离 android 应用的本机代码符号

How to avoid stripping for native code symbols for android app

我在本机代码中得到 sigsegv 11,我需要避免剥离以了解问题所在。该应用程序使用库 (aar),我能够避免使用 'cmd-strip' 剥离 aar。但是在 apk 剥离版本中无论如何都使用 .so 所以应用程序剥离符号,可能是 transformNative_libsWithStripDebugSymbolForDebug gradle 任务。有什么改变可以避免吗?

PS。在 SO 上找到 similar question,但它有点不同(在我的例子中使用 aar 而没有剥离符号)。

幸运的是,您实际上不需要将符号保留在应用程序中。 NDK 附带了一个名为 ndk-stack 的工具(它位于 NDK 的根目录中),它可以为您标记堆栈跟踪:https://developer.android.com/ndk/guides/ndk-stack.html

packagingOptions 中有一个未记录的方法 'doNotStrip',只需在 build.gradle

中添加以下行
packagingOptions{
    doNotStrip "*/armeabi/*.so"
    doNotStrip "*/armeabi-v7a/*.so"
    doNotStrip "*/x86/*.so"
}