11

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.

This is how the config looks:

buildTypes {
    debug {
        minifyEnabled true
        proguardFiles 'proguard-debug.pro'
        testProguardFile 'proguard-debug.pro'
        signingConfig signingConfigs.release
    }
}

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

Before someone starts to advise me turning off proguard for debug builds: I need to have it enabled because of multidex.

2 Answers 2

12

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'
}

and

# proguard-test.pro:
-include proguard-rules.pro
-keepattributes SourceFile,LineNumberTable

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.

3

You also need to add the default proguard rules:

proguardFiles getDefaultProguardFile('proguard-android.txt')

This line can be removed, as it is a duplicate:

testProguardFile 'proguard-debug.pro'
1
  • 2
    Seems nowadays testProguardFiles doesn't work anymore
    – sandrstar
    Commented Aug 11, 2021 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.