1

I'm using Proguard to shrink my debug apk and test apk

buildTypes {
    debug {
        applicationIdSuffix ".debug"
        debuggable true
        signingConfig signingConfigs.debug
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        testProguardFile 'proguard-test-rules.pro'
    }

When I enable minify and run integration tests, the debug apk method count reduces, but not the test apk.

I know that Proguard is doing something, because if I don't have the right rules in proguard-test-rules.pro I'll see warnings and the test apk won't compile.

So what's happening? Why isn't my test apk shrinking? Just for reference, here are my .pro files:

proguard-rules.pro:

# general
-dontobfuscate

# for Retrofit2
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

# for RetroLambda
-dontwarn java.lang.invoke.*

# for Saripaar
-keep class com.mobsandgeeks.saripaar.** {*;}
-keep @com.mobsandgeeks.saripaar.annotation.ValidateUsing class * {*;}

# for OKIO
-dontwarn okio.**

# for RxJava
-dontwarn sun.misc.Unsafe

# for android.content.res classes
-dontwarn org.xmlpull.v1.**

# for Butterknife
-dontwarn rx.functions.Func1

proguard-test-rules.pro

-include proguard-rules.pro

-dontobfuscate
-dontwarn

-dontwarn org.hamcrest.**
-dontwarn android.test.**

-dontwarn android.support.test.**
-keep class android.support.test.** { *; }

-keep class junit.runner.** { *; }
-keep class junit.framework.** { *; }
-keep class org.jmock.core.** { *; }
-keep class org.easymock.** { *; }


-dontwarn com.fasterxml.jackson.databind.**
-dontwarn com.fasterxml.jackson.core.**
-dontwarn com.fasterxml.jackson.annotation.**
-dontwarn org.ietf.jgss.**
-dontwarn javax.xml.**
-dontwarn javax.swing.**
-dontwarn javax.lang.**
-dontwarn java.nio.**
-dontwarn java.lang.**
-dontwarn org.w3c.dom.traversal.**
-dontwarn org.eclipse.jetty.**
-dontwarn java.beans.**
-dontwarn org.slf4j.**
-dontwarn org.apache.http.**
tir38
  • 9,810
  • 10
  • 64
  • 107
  • Did you ever solve this? I am having same problem trying to reduce method count for test apk. – roko Oct 11 '17 at 10:12
  • @roko no, this was the issue i opened: https://issuetracker.google.com/issues/37134017 – tir38 Oct 31 '17 at 14:53

1 Answers1

0

ProGuard runs only when you build your application in release mode, so you do not have to deal with obfuscated code when you build your application in debug mode or in test mode. Building in debug mode or test does not invoke ProGuard, because it makes debugging more cumbersome. Check this link

Anurag Singh
  • 6,140
  • 2
  • 31
  • 47
  • 3
    That is a dated answer, as explained here http://stackoverflow.com/a/16559793/1650674. Furthermore, the *actual* documentation on this directly refutes what you're saying. "Be aware that code shrinking slows down the build time, so you should avoid using it on your debug build if possible." https://developer.android.com/studio/build/shrink-code.html Lastly, as I said in my question, Proguard is working fine for the debug apk, but not the test apk. – tir38 Jan 25 '17 at 20:24