将proguard与espresso/androidTest一起使用 [英] Using proguard with espresso/androidTest
问题描述
我正在尝试将proguard配置为与我的espresso UI测试版本一起使用.问题是Proguard倾向于忽略我的调试Proguard配置.
I'm trying to configure proguard to use it with my espresso UI test flavor. The thing is Proguard tends to ignore my debug proguard config.
这是配置的外观:
buildTypes {
debug {
minifyEnabled true
proguardFiles 'proguard-debug.pro'
testProguardFile 'proguard-debug.pro'
signingConfig signingConfigs.release
}
}
我添加了testProguardFile
,但在androidTest
上似乎不起作用.我正在运行mockDebug
风味变体.当我只运行该应用程序时,它运行良好,但是当我尝试运行位于adnroidTest
中的测试时,由于proguard警告,它将无法运行,例如根本没有处理proguard文件,并且该文件很直前进:
I added testProguardFile
but it doesn't seem to work on androidTest
. I'm running mockDebug
flavor variant. When I just run the app it works fine, but when I try to run test which is located in adnroidTest
it won't run due to proguard warnings, like the proguard file wasn't processed at all and the file is pretty straight forward:
proguard-debug.pro
-dontobfuscate
-dontoptimize
-dontwarn
在有人开始建议我关闭用于调试版本的proguard之前:由于multidex,我需要启用它.
Before someone starts to advise me turning off proguard for debug builds: I need to have it enabled because of multidex.
推荐答案
如果您希望测试与实际交易尽可能接近,请尝试以下方法:
If you want your test build as close as possible from the real deal, try this one:
# build.gradle
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testProguardFile 'proguard-test.pro'
}
和
# proguard-test.pro:
-include proguard-rules.pro
-keepattributes SourceFile,LineNumberTable
另一方面,如果仅因为多dex而需要它,请如果您使用的是minSdkVersion< 21,ProGuard与multidex标志绑定并自动运行.
On other hand, if you need it only because multidex, if your are using minSdkVersion < 21, ProGuard is tied to multidex flag and run automatically.
这篇关于将proguard与espresso/androidTest一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!