2

I am using Guava in a Android project. I am hitting the 65k method limit which fails the gradle build. I found that this could be resolved by using proguard. I run Proguard on release build and it works fine. I do not want to run proguard on debug build as it makes debugging hard. I was wondering if there is a way to resolve this? One option I am considering is to build a local guava.jar and defining that as a dependency instead of pulling it from maven central. Is there a better way to do this?

bond
  • 11,236
  • 7
  • 48
  • 62
  • It's not terrible to run ProGuard on debug builds - it will help you catch any ProGuard configuration errors early, rather than trying to track them all down in your release build. – stkent Mar 11 '15 at 02:20
  • Running proguard everytime in debug builds will waste a lot of time. Can you check the method counts for all the libraries you are using? Are you using stripped down versions of google play services or not? – Gaurav Vashisth Mar 11 '15 at 03:57
  • Thanks @Gaurav, I am using stripped versions of google play services, right now guava is the biggest offender with 14K+ methods alone. – bond Mar 11 '15 at 04:02
  • Can you exclude some packages from the guava lib, by using the 'exclude in the gradle dependencies. – Gaurav Vashisth Mar 11 '15 at 04:08
  • I inspected the dependencies and found that I they are mostly using "common.collect.", package, but stuff there have references to others. For now I am able to use jarjar to build a jar with classes in that package. – bond Mar 11 '15 at 04:17

2 Answers2

1

Latest Android build tools support MultiDex option. This allows to build apps with over 65k methods. Just follow the official guide.

Also you can enable automatic resource shrinking alongside with ProGuard:

android {
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
        }
    }
}
Kirill Boyarshinov
  • 6,143
  • 4
  • 33
  • 29
0

According to the official doc of Guava, you can use the following:

-injars path/to/myapplication.jar
-injars lib/guava-r07.jar
-libraryjars lib/jsr305.jar
-outjars myapplication-dist.jar

-dontoptimize
-dontobfuscate
-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue

-keepclasseswithmembers public class * {
    public static void main(java.lang.String[]);
}

This will keep your methods with the same name without obfuscating. Meaning that you can still debug properly with all the appropriate names written as is.

user4989692
  • 1,609
  • 1
  • 20
  • 25
Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137
  • So how would you set this up for your debug build such that this only applies to guava jar only? I am already using proguard for release build and that works. – bond Mar 11 '15 at 10:37
  • I did find http://stackoverflow.com/questions/16559723/is-it-possible-to-use-proguard-in-debug-mode but this still makes it hard to debug – bond Mar 11 '15 at 10:40