我们有一个具有一些库(和 native )依赖项的项目,如下所示:
原生 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 进行测试吗?
最佳答案
一种选择是使用 testBuildType
将测试构建更改为发布构建或启用了 ProGuard 的其他构建变体。请参阅Gradle User Guide 。您也可以尝试解决方案 here ,但我自己没有尝试过。
关于android - 如何在 Android 上运行 ProGuard 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31705341/