【问题标题】:Using Common Proguard File in Multi-Application-Module Android Project在多应用模块 Android 项目中使用通用 Proguard 文件
【发布时间】:2022-08-25 20:49:07
【问题描述】:

我在我们现有的 Android 移动应用程序中创建了一个 Wear OS 模块。两个应用程序模块都保留在项目中,如下所示:

Project/app
Project/wear/wear_presentation
Project/otherLibModule/other_lib_module_presentation

我们有一个common.gradleappwear_presentation 使用:

    buildTypes {
        release {
            minifyEnabled true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

        debug {
            debuggable true
            minifyEnabled false
        }
    }

在 Wear OS 模块之前,我们在 app 模块中只有一个 proguard 文件来处理所有缩小工作,但现在我们有 2 个应用程序模块,它们具有单独的 proguard 文件。这迫使我将app proguard 文件中的所有内容复制/粘贴到wear_presentation proguard 文件中,这种方法似乎很业余。

我想使用appwear_presentation 模块都使用的单个通用proguard 文件。

可能吗?

【问题讨论】:

    标签: android proguard wear-os


    【解决方案1】:

    已经支持从库导入。

    https://developer.android.com/studio/build/shrink-code#configuration-files

    /proguard.txt - If an AAR library is published with its own ProGuard rules file, and you include that AAR as a compile-time dependency, R8 automatically applies its rules when compiling your project.

    如果库需要某些保留规则才能正常运行,则使用与 AAR 库打包的规则文件很有用——也就是说,库开发人员已经为您执行了故障排除步骤。

    但是,您应该知道,由于 ProGuard 规则是附加的,AAR 库依赖项包含的某些规则无法删除,并且可能会影响应用程序其他部分的编译。例如,如果库包含禁用代码优化的规则,则该规则会禁用整个项目的优化。 /META-INF/proguard/ - 用于 JAR 库

    它被 OkHttp https://github.com/square/okhttp/blob/okhttp_4.10.x/okhttp/src/main/resources/META-INF/proguard/okhttp3.pro 等库常用

    【讨论】:

      猜你喜欢
      • 2018-03-25
      • 2021-12-29
      • 2015-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      相关资源
      最近更新 更多