com.android.dex.DexIndexOverflowException:(包括Android Studio3.0之前和之后解决方案)

本文介绍了解决Android开发中常见的DEX64K问题的方法。针对不同版本的Android Studio,提供了详细的步骤来启用MultiDex支持,包括配置build.gradle文件及AndroidManifest.xml等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

AS2.2解决方案:三步

一、项目目录下build.gradle 下的defaultConfig添加multiDexEnabled true

二、项目目录下build.gradle 下的dependencies

三、AndroidManifest.xml中添加 android:name = "android.support.multidex.MultiDexApplication"

AS3.0.1解决方案:

一、在app的build.gradle下:

 二、在项目的build.gradle下:

 三、AndroidManifest.xml中添加 android:name = "android.support.multidex.MultiDexApplication"


Error:(58, 13) Failed to resolve: com.android.support:multidex:

问题:com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65535.  这就是著名的DEX 64K问题,据说是Dalvik当初设计单个DEX最多可以存放65536方法的ID,所以如果方法数过多就会出现这个问题。

直接原因是Java代码太多,jar包太多。

 

AS2.2解决方案:三步

一、项目目录下build.gradle 下的defaultConfig添加multiDexEnabled true

defaultConfig{  
   multiDexEnabled true  
} 

二、项目目录下build.gradle 下的dependencies

compile 'com.android.support:multidex:'

三、AndroidManifest.xml中添加 android:name = "android.support.multidex.MultiDexApplication"

如果项目中已经使用了Applicaiton,可以提供的解决方法是让自己的Application继承MultiDexApplication或者在Application的attachBaseContext方法中添加

@Override    
  protected void attachBaseContext(Context base) {    
    super.attachBaseContext(base);    
    MultiDex.install(this);  
 }   

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

以上在android studio2.2上使用时没问题的,但是在3.0.1上就解决不了问题了

AS3.0.1解决方案:

一、在app的build.gradle下:

1、

 

 

defaultConfig{  
   multiDexEnabled true  
} 

 2、

 

dependencies {

    //解决问题:com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
    //这就是著名的DEX 64K问题,据说是Dalvik当初设计单个DEX最多可以存放65536方法的ID,所以如果方法数过多就会出现这个问题。
    // 直接原因是Java代码太多,jar包太多。
    compile 'com.android.support:multidex:1.0.2'

}

 二、在项目的build.gradle下:

buildscript {
    
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        
    }
}

allprojects {
    repositories {
        jcenter()
        google()
        maven {
            url 'https://maven.google.com'
        }
    }
}

或者这样也可以:

buildscript {
    
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
        maven {
//            url 'https://maven.google.com'
            url 'https://jitpack.io'
        }
    }
}

 

 三、AndroidManifest.xml中添加 android:name = "android.support.multidex.MultiDexApplication"

如果项目中已经使用了Applicaiton,可以提供的解决方法是让自己的Application继承MultiDexApplication或者在Application的attachBaseContext方法中添加

@Override    
  protected void attachBaseContext(Context base) {    
    super.attachBaseContext(base);    
    MultiDex.install(this);  
 }   

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值