Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536

方法数超过了限制

Eclipse报错:Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536
Android Studio报错:Error:The number of method references in a .dex file cannot exceed 64K.
这里写图片描述

Studio很智能,还提供给你解决这个问题的网站
当然解决方案也在这个网站里面:https://developer.android.com/studio/build/multidex.html

解决方案是: Android引入multidex包, 他会根据方法数, 生成多个dex文件.
只需要配置下依赖, 然后在application 类里面修改继承关系, 然后初始化就可以解决了

配置build.gradle

android {
     compileSdkVersion 21
     buildToolsVersion "21.1.0"
     defaultConfig {
          ...
          minSdkVersion 14
          targetSdkVersion 21
          ...
          // Enabling multidex support.
          multiDexEnabled true
     }
     ...
}
dependencies{
     compile 'com.android.support:multidex:1.0.0'//dependencies
}

androidManifest.xml中application中声明android.support.multidex.MultiDexApplication;

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

或自己定义一个Application类,继承自MultiDexApplication;
或者自己定义的Application类,在attachBaseContext()方法中,添加MultiDex.install(this);

public class BaseApplication extends MultiDexApplication{

     public void onCreate(Bundle arguments) {
         MultiDex.install(getTargetContext());
         super.onCreate(arguments);
         ...
     }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值