将 doNotStrip packagingOptions 设置为特定的 buildType [英] Set doNotStrip packagingOptions to a specific buildType

查看:41
本文介绍了将 doNotStrip packagingOptions 设置为特定的 buildType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有 3 种不同的 buildTypes,我只需要其中一种来保存其本机库的调试信息.我正在使用 com.android.tools.build:gradle:3.1.4.

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.

我尝试了以下

buildTypes {

   debug {
   ...
   }

   release {
   ...
   }

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

但这使得所有 buildTypes 都保留未剥离的库版本.

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

我还尝试将 doNotStrip 模式更改为 '**/unstripped/*.so' 之类的模式,但这似乎对我没有帮助,因为 docs 说该路径与 APK 的根目录相关.

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.

推荐答案

这里有一个解决方法:

提供命令行选项doNotStrip"

Feeding a command line option "doNotStrip"

  1. 将以下内容添加到您的 app/build.gradle

android {
    ...
    if (project.hasProperty("doNotStrip")) {
        packagingOptions {
            doNotStrip '**/*.so'
        }
    }
    ...
}

  • 通过将选项 doNotStrip 提供给命令,使用以下命令生成 未剥离的 apk.

  • Use below command to generate the unstripped apk by feeding option doNotStrip to the command.

    ./gradlew assembleUnstripped -PdoNotStrip
    

  • 对于其他构建类型,您仍然可以使用正常的构建命令.例如

  • For other build types, you can still use the normal build commands. e.g.

    ./gradlew assembleDebug
    

    ./gradlew assembleRelease
    

    但不要将选项 doNotStrip 提供给命令.

    but don't feed option doNotStrip to the command.

    这篇关于将 doNotStrip packagingOptions 设置为特定的 buildType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆