Set doNotStrip packagingOptions to a specific buildType

Viewed 5546

My project has 3 different buildTypes and I need only one of them to keep the debug info of its native libraries. I'm using com.android.tools.build:gradle:3.1.4.

I tried the following

buildTypes {

   debug {
   ...
   }

   release {
   ...
   }

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

but that makes all buildTypes to keep unstripped versions of the libraries.

I also tried changing the doNotStrip pattern to something like '**/unstripped/*.so' but that does not seem to help me, since the docs say that the path is related to the APK's root dir.

1 Answers

Here is a workaround for you:

Feeding a command line option "doNotStrip"

  1. Add below to your app/build.gradle

    android {
        ...
        if (project.hasProperty("doNotStrip")) {
            packagingOptions {
                doNotStrip '**/*.so'
            }
        }
        ...
    }
    
  2. Use below command to generate the unstripped apk by feeding option doNotStrip to the command.

    ./gradlew assembleUnstripped -PdoNotStrip
    
  3. For other build types, you can still use the normal build commands. e.g.

    ./gradlew assembleDebug
    

    or

    ./gradlew assembleRelease
    

    but don't feed option doNotStrip to the command.

Related