Home > Software design >  How to include debug symbols for a pre-built native library inside an Android App Bundle?
How to include debug symbols for a pre-built native library inside an Android App Bundle?

Time:07-19

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.

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."

In the past when uploading apps as .apk files it was necessary to manually upload such debug info. 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.

pre-built libraries

However its not always possible/ideal/necessary to build a library inside 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 supports this via a directory structure which is described here Contents of a sample ..ab

CodePudding user response:

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.

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). 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.

Ultimately all you need to do to make this work is:

  1. Build your external .so files with -g -g3 or similar
  2. Do not strip them in any way
  3. Place them in jniLibs directory structure un-stripped
  4. Configure your build.gradle appropriately 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.

  • Related