Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using proguard with espresso/androidTest

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.

like image 551
Jacek Kwiecień Avatar asked Jun 07 '16 08:06

Jacek Kwiecień


2 Answers

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.

like image 112
chrisandrew.cl Avatar answered Sep 23 '22 02:09

chrisandrew.cl


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'
like image 24
T. Neidhart Avatar answered Sep 22 '22 02:09

T. Neidhart