【问题标题】:How to run ProGuard on Android tests?如何在 Android 测试中运行 ProGuard?
【发布时间】:2015-07-29 15:52:16
【问题描述】:

我们有一个带有一些库(和本机)依赖项的项目,如下所示:

原生 SDK ← 库(包装器)← 主项目

首先,此结构不能更改,因为我们正在重复使用这些部分。我面临的问题是通过了 65k 参考限制。当然,这有一个解决方法 - 启用 ProGuard。启用它后,项目将编译。

由于我们正在过渡到 Android 的默认测试框架,我们需要在测试配置中添加更多依赖项,所以在依赖项中我们现在拥有:

compile 'com.google.android.gms:play-services-base:7.5.0'
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-safetynet:7.5.0'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'

compile files('libs/small-library1.jar')
compile files('libs/small-library2.jar')
compile files('libs/small-library3.jar')
compile files('libs/medium-library1.jar')
compile files('libs/medium-library2.jar')
compile files('libs/medium-library3.jar')
compile files('libs/huge-library1.jar')
compile files('libs/huge-library2.jar')

androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'

我们使用的是 SDK (API) 22,所以几乎所有内容都是最新版本。问题是,我们的原生 SDK 在 protobuf 层有一堆代码,而且库包装器很大。对于所有其他 JAR,我们超过了 65k 的限制(但正如我所说,ProGuard 几乎没有解决这个问题)。 Multi-dex 是不可能的,因为它只在 Android 5.0+ 上运行良好。

我们正在尝试减少代码库,但即便如此,Android 测试仍因方法引用溢出问题(即无法编译)而失败。

有什么方法可以同时启用 ProGuard 进行测试?

【问题讨论】:

    标签: android testing gradle junit proguard


    【解决方案1】:

    一种选择是使用 testBuildType 将您的测试构建更改为发布构建或启用 ProGuard 的另一个构建变体。见Gradle User Guide。你也可以试试here的解决方案,不过我自己没试过。

    【讨论】:

    • 我已经测试了来自stackoverflow.com/questions/21463089/… 的解决方案,但没有运气。我现在会检查另一个。
    • 所以第一个也失败了。我已将testBuildType = "release" 添加到android 标记中,但proguard 仍然没有运行..
    • 我试过staging变种,再次得到dex溢出错误(这意味着项目太大)。我会接受这个答案,因为它确实解决了 proguard 不在测试版本上运行的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    相关资源
    最近更新 更多