bond
bond

Reputation: 11336

Android project with Guava hitting the limit

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?

Upvotes: 2

Views: 1526

Answers (2)

Olivier Grégoire
Olivier Grégoire

Reputation: 35427

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.

Upvotes: 0

Kirill Boyarshinov
Kirill Boyarshinov

Reputation: 6163

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

Upvotes: 1

Related Questions