Search code examples
androidandroid-ndkandroid-build

java.lang.OutOfMemoryError when packaging an Android App with the native libs


all:

I have an Android App with the NDK-build enabled, the size of the native shared library with the debug symbols is about 2G. In my Gradle script, there is a packaging option,

  packagingOptions {
    doNotStrip '**/*testcore*.so'
  }

If I commented out the block, I can run the App without problems. If I leave the block to run/debug the App, I will get the out-of-memory issue during the packaging task, like this:

Execution failed for task ':app:packageXXXXXXXXDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > java.lang.OutOfMemoryError (no error message)

I have tried to increase the memory in the file gradle.properites to a big number,

org.gradle.jvmargs=-Xmx8g

It seems not to help too much. I am using Android Studio 4.1.1 with plugin 4.0.1. (It works before with Android Studio 4.0.1 with 3.5.0).

Since we need to debug step-into the native code often, we need to deploy the native lib without stripping the debug symbols. Any suggestion or solution? thanks!


Solution

  • I would suggest to strip the symbols while packaging the APK and then while debugging, let LLDB know the location of unstripped binaries through by adding it to search path https://stackoverflow.com/a/38426653/5954246 or simpler, by using target symbols add <file>.so. LLDB automatically maps the stripped symbol file to sources, so hopefully this should work.