对Too many classes in --main-dex-list,main dex capacity exceded提供简单几种方案。

对Too many classes in –main-dex-list,main dex capacity exceded提供简单几种方案。

问题:
对Too many classes in --main-dex-list,main dex capacity exceded提供简单几种方案。_第1张图片
这个问题出现在使用分包库后,main-dex里面的方法数超出。
gradle plugin版本:2.+
gralde 版本:2.10+
简单提供一些解决方案:
1、使用Android官方提供方案,见Configure Apps with Over 64K Methods,里面这样说的,

Avoiding the 64K Limit
Before configuring your app to enable use of 64K or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or included libraries. The following strategies can help you avoid hitting the dex reference limit:

Review your app’s direct and transitive dependencies - Ensure any large library dependency you include in your app is used in a manner that outweighs the amount of code being added to the application. A common anti-pattern is to include a very large library because a few utility methods were useful. Reducing your app code dependencies can often help you avoid the dex reference limit.
Remove unused code with ProGuard - Configure the ProGuard settings for your app to run ProGuard and ensure you have shrinking enabled for release builds. Enabling shrinking ensures you are not shipping unused code with your APKs.
Using these techniques can help you avoid the build configuration changes required to enable more method references in your app. These steps can also decrease the size of your APKs, which is particularly important for markets where bandwidth costs are high.
还说了要配合使用Android官方提供的分包库。当然这个方案是可以解决目前我们提出的这个问题的。但是如果是在开发环境中去使用proguard的话,请问还让苦逼的程序员怎么调试?心塞啊。。。
所以我们强大的酷狗的同学们提出的解决方案,作为内部技术,目前好像还没有开源出来,这样就不贴出来了。但是酷狗同学提出的方法问题是可以解决,但是解决前要经历一次阵痛,我在尝试几次后,果断放弃。其中的阵痛比用Proguard方案要痛苦多了。
于是后来我找到了一个简单有效的方案,目前暂时解决了问题。在工程目录下的build.gradle中修改:

dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0-alpha4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

好了,现在让我们安静的做一个程序员吧。:)。。。。

你可能感兴趣的:(android分享)