简体   繁体   English

如何在 Android App Bundle 中包含预构建本机库的调试符号?

[英]How to include debug symbols for a pre-built native library inside an Android App Bundle?

Background info背景资料

When uploading an app to the play store that uses a native library its necessary to also upload the native debug symbols to get useful crash/ANR info.将应用程序上传到使用本机库的 Play 商店时,还需要上传本机调试符号以获取有用的崩溃/ANR 信息。

If you upload without symbols you receive the following warning: "This App Bundle contains native code, and you've not uploaded debug symbols. We recommend you upload a symbol file to make your crashes and ANRs easier to analyze and debug."如果您上传时没有符号,您会收到以下警告:“此 App Bundle 包含本机代码,并且您尚未上传调试符号。我们建议您上传符号文件,以使您的崩溃和 ANR 更易于分析和调试。”

In the past when uploading apps as .apk files it was necessary to manually upload such debug info.过去在将应用程序上传为.apk文件时,需要手动上传此类调试信息。 Now using .aab if the native library is built via android studio its possible to set android.defaultConfig.ndk.debugSymbolLevel = 'FULL' at which point when you build a the .aab it will include the debug info automatically, you upload this single file and everything is done/working.现在使用.aab如果本机库是通过 android studio 构建的,则可以设置android.defaultConfig.ndk.debugSymbolLevel = 'FULL' ,此时当您构建.aab时,它将自动包含调试信息,您上传此单文件,一切都已完成/工作。

pre-built libraries预建库

However its not always possible/ideal/necessary to build a library inside android studio.然而,在 android studio 中构建库并不总是可能/理想/必要的。 Sometimes there are reasons for libraries to be externally pre-built and just used by android studio not built by it;有时有一些原因需要在外部预先构建库并仅由 android studio 使用,而不是由它构建; Android studio supports this via a directory structure which is described here https://developer.android.com/studio/projects/gradle-external-native-builds#jniLibs In short you just copy the libraries into the correct src/main/jniLibs/{ABI} path(s) and it is picked up and made part of the bundle. Android Studio 通过此处描述的目录结构支持这一点https://developer.android.com/studio/projects/gradle-external-native-builds#jniLibs简而言之,您只需将库复制到正确的src/main/jniLibs/{ABI}路径,它被拾取并成为捆绑包的一部分。

Problem问题

  • Android studio can build a .aab that contains debug info that play store can understand so that you don't need to upload it manually. Android Studio 可以构建一个.aab ,其中包含 Play 商店可以理解的调试信息,因此您无需手动上传。
  • Android studio can use pre built native libraries if you place them in the right path structure如果您将它们放置在正确的路径结构中,Android Studio 可以使用预构建的原生库
  • I am unable to find any documentation or way to do both of these things together, use native pre-built libraries but include their debug info in the .aab .我无法找到任何文档或方法来同时执行这两项操作,使用本地预构建库,但在.aab中包含它们的调试信息。 Even though logically it should be possible to do this.即使在逻辑上应该可以做到这一点。

I have searched everywhere I think but can't find anyone even talking about this really, how/where do you place the corresponding debug information so that that also can be included as part of the .aab ?我已经搜索了我认为的所有地方,但找不到任何人甚至真的在谈论这个,您如何/在哪里放置相应的调试信息,以便也可以将其作为.aab的一部分包含在内? Is there a separate path for this, do they just need a specific file extension, does gradle need to be told what to do with them somehow?是否有单独的路径,它们是否只需要特定的文件扩展名,是否需要告诉 gradle 以某种方式处理它们? Is it really just not possible?这真的不可能吗?

Things I have tried:我尝试过的事情:

  • Don't split the debug info just leave them in the .so files - play store does not strip them then so you deliver giant debug versions of your builds to your users不要拆分调试信息,只需将它们留在 .so 文件中 - Play 商店不会剥离它们,因此您可以向用户提供构建的巨大调试版本
  • Split the debug info into files with .so.dbg extension and place them alongside the .so files - they aren't included in the .aab将调试信息拆分为扩展名为.so.dbg的文件,并将它们放在 .so 文件旁边 - 它们不包含在.aab
  • Following the instructions (here https://support.google.com/googleplay/android-developer/answer/9848633 and elsewhere) to manually zip and upload the symbols after uploading the .aab - this appears to work but isn't the same convenience wise as having them in the .aab按照说明(此处为https://support.google.com/googleplay/android-developer/answer/9848633和其他地方)在上传.aab后手动压缩和上传符号 - 这似乎有效但不一样将它们放在.aab中一样方便
  • I've tried building a sample app with android studio building a lib instead of using a pre-built lib just to verify that it does then include the debug info and what file extension it uses.我尝试使用 android studio 构建一个示例应用程序来构建一个库,而不是使用预构建的库来验证它是否包含调试信息以及它使用的文件扩展名。 样本内容..ab

After some more digging I found the task responsible for this is "ExtractNativeDebugMetadataTask" with which some effort can likely be tailored/altered to do custom things here.经过更多挖掘后,我发现负责此任务的任务是“ExtractNativeDebugMetadataTask”,可以通过它来定制/更改一些工作以在此处执行自定义操作。

However this ended up being unnecessary as while digging into this I discovered that it actually already works.然而,这最终是不必要的,因为在深入研究时我发现它实际上已经有效。 At least as of now in latest gradle versions (not sure about the past).至少到目前为止最新的 gradle 版本(不确定过去)。 It was only failing due to some NDK path confusion which doesn't fail the build/creation of the bundle building but just logs an easy to miss informational message.它只是由于某些 NDK 路径混淆而失败,这不会导致包构建的构建/创建失败,但只会记录一条容易错过的信息消息。

Ultimately all you need to do to make this work is:最终,完成这项工作所需要做的就是:

  1. Build your external .so files with -g -g3 or similar使用-g -g3或类似工具构建您的外部.so文件
  2. Do not strip them in any way不要以任何方式剥离它们
  3. Place them in jniLibs directory structure un-stripped将它们放在未剥离的jniLibs目录结构中
  4. Configure your build.gradle appropriately android{ ndk { debugSymbolLevel 'FULL' } ndkPath "$projectDir/path/to/NDK" }适当配置你的 build.gradle android{ ndk { debugSymbolLevel 'FULL' } ndkPath "$projectDir/path/to/NDK" }

Resulting .aab will contain the stripped .so files and the split-debug .so.dbg files all in the right location.生成的.aab将在正确的位置包含剥离的.so文件和拆分调试的.so.dbg文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM