android 方法数超过,android方法数超过64K的解决方案

在android开发的过程中,随着app的功能和代码的增加,总会在一次编译后遇到这个错误:

Conversion to Dalvik format failed:

Unable to execute dex: method ID not in [0, 0xffff]: 65536

这就是android中方法数超过64k,即64 * 1024位数的限制。在android官方api中给出了这个问题的解决方案《配置方法数超过 64K 的应用》,让你完美的规避64k的限制。

1.如果你的minSdkVersion的设置>=21,只需要在build.gradle中设置multiDexEnabled为true

android {

defaultConfig {

...

minSdkVersion 21

targetSdkVersion 26

multiDexEnabled true

}

...

}

2.如果你的minSdkVersion的设置<21,就需要如下操作了

1.在AndroidMainfest.xml中添加application。

package="com.example.myapp">

android:name="MyApplication" >

...

2.调用attachBaseContent()方法调用Multidex.install(this)。

public class MyApplication extends SomeOtherApplication {

@Override

protected void attachBaseContext(Context base) {

super.attachBaseContext(context);

Multidex.install(this);

}

}

3.build.gradle中添加

android {

defaultConfig {

...

minSdkVersion 15

targetSdkVersion 26

multiDexEnabled true

}

dexOptions {

incremental true

javaMaxHeapSize "4g"

}

...

}

dependencies {

compile 'com.android.support:multidex:1.0.1'

}

就搞定了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值