与番石榴的Android项目达到极限

时间:2015-03-11 01:57:36

标签: android proguard guava android-gradle android-guava

我在Android项目中使用Guava。我正在达到65k方法限制,这使得gradle构建失败。我发现这可以通过使用proguard来解决。我在发布版本上运行Proguard,它工作正常。我不想在调试版本上运行proguard,因为它会使调试变得困难。我想知道是否有办法解决这个问题?我正在考虑的一个选择是构建一个本地guava.jar并将其定义为依赖,而不是从maven中心拉出它。有更好的方法吗?

2 个答案:

答案 0 :(得分:1)

最新的Android构建工具支持MultiDex选项。这允许使用超过65k的方法构建应用程序。只需按照official guide

此外,您还可以启用自动资源缩减以及ProGuard:

android {
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
        }
    }
}

答案 1 :(得分:0)

根据official doc of Guava,您可以使用以下内容:

-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[]);
}

这将使您的方法保持相同的名称而不会混淆。这意味着您仍然可以使用所有适当的名称正确调试。

相关问题