繁体   English   中英

如何在 Android 测试中运行 ProGuard?

[英]How to run ProGuard on Android tests?

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

Native SDK ← Library (Wrapper) ← 主项目

首先,这种结构不能改变,因为我们正在重复使用这些部件。 我面临的问题是通过 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 吗?

一种选择是使用testBuildType将您的测试构建testBuildType为发布构建或启用 ProGuard 的另一个构建变体。 请参阅Gradle 用户指南 您也可以在这里尝试解决方案,但我自己没有尝试过。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM