目录
一、项目目录下build.gradle 下的defaultConfig添加multiDexEnabled true
二、项目目录下build.gradle 下的dependencies
三、AndroidManifest.xml中添加 android:name = "android.support.multidex.MultiDexApplication"
三、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);
}