Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

proguard gradle debug build but not the tests

I enabled proguard for the debug build using:

android {
    buildTypes {
        debug {
            runProguard true
            proguardFile 'proguard-debug.txt'
        }
        release {
            runProguard true
            proguardFile 'proguard-project.txt'
            zipAlign true
        }
    }
}

The problem I'm experiencing when I do this is that the gradle build wants to proguard the tests during the proguardDebugTest task as well. I can't seem to modify to get access to this particular task. Is there a way I can proguard the debug apk but not the test apk?

like image 838
Apparent Visuals Avatar asked Jan 30 '14 17:01

Apparent Visuals


People also ask

How do I enable ProGuard in debug build?

Enabling ProGuard (Gradle Builds)Set the minifyEnabled property to true to enable ProGuard, as shown in this example. The getDefaultProguardFile('proguard-android. txt') method obtains the default ProGuard settings from the Android SDK tools/proguard/ folder.

How to ignore warnings in ProGuard?

There is no option to switch off these warnings. The standard Android build process automatically specifies the input jars for you. There may not be an easy way to filter them to remove these warnings. You could remove the duplicate resource files manually from the input and the libraries.

What is Dontwarn in ProGuard?

If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options. ( http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)


1 Answers

runProguard is old. It was replaced with minifyEnabled

With minifyEnabled (and other changes in new versions of gradle) you will may encounter issues where the proguard config works for your debug apk but not for the instrumentation tests. The apk created for instrumentation tests will use its own proguard file, so changing your existing proguard file will have no effect.

In this case, you need to specify the proguard file to use on the instrumentation tests. It can be quite permissive because it's not affecting your debug and release builds at all.

    // inside android block
    debug {
        shrinkResources true  // removes unused graphics etc
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        testProguardFile('test-proguard-rules.pro')
    }
like image 109
user823629 Avatar answered Nov 16 '22 03:11

user823629