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

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

问题:
这里写图片描述
这个问题出现在使用分包库后,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
    }

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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值