Programing

최신 appcompat 및 지원 라이브러리로 업데이트 한 후 DexIndexOverflowException 문제

crosscheck 2020. 10. 23. 07:36
반응형

최신 appcompat 및 지원 라이브러리로 업데이트 한 후 DexIndexOverflowException 문제


다음을 통해 아래 설정을 사용하고 있습니다 gradle.

compileSdkVersion 21
ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.0.2
ANDROID_BUILD_SDK_VERSION=21

또한 내 gradle 파일에 다음 설정이 있습니다.

compile 'com.android.support:support-annotations:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:support-v4:21.0.0'

항상 오류가 발생 UNEXPECTED TOP LEVEL EXCEPTION합니다.
나는 할 때 21.0.0까지 20.0.0그것을 잘 작동합니다 ...하지만 난 안드로이드 API (21) 옵션을 액세스 할 수 없습니다입니다. 내가 여기서 잘못하고있는 것이 있습니까? 이 예외없이 컴파일하려면 어떻게해야합니까? 다른 학년 프로젝트 (페이스 북 등) 외에 다른 곳에 지원 항아리가 없습니다.

다음은 전체 스택 추적입니다.

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
    at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
    at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:283)
    at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
    at com.android.dx.command.dexer.Main.run(Main.java:245)
    at com.android.dx.command.dexer.Main.main(Main.java:214)
    at com.android.dx.command.Main.main(Main.java:106)

이 메시지는 프로젝트가 너무 큰 것 같습니다.

방법이 너무 많습니다. dex에 대한 메서드는 65536 개만있을 수 있습니다 .

gradle 플러그인 0.14.0 및 빌드 도구 21.1.0부터 multidex 지원을 사용할 수 있습니다 .

다음 줄을 추가하십시오 build.gradle.

android {

    defaultConfig {
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

또한 multidex 지원 라이브러리 ManifestMultiDexApplication클래스를 애플리케이션 요소에 추가하십시오.

<?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클래스를 사용하는 경우 상위 클래스를에서 Application변경하십시오 MultiDexApplication.


1) 애플리케이션 build.gradle 파일에 종속성 추가

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

2) Application 클래스를 재정의하지 않는 경우 매니페스트 파일을 편집하여 다음과 같이 태그에 android : name을 설정합니다.

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

Application 클래스를 재정의하는 경우 다음과 같이 MultiDexApplication (가능한 경우)을 확장하도록 변경합니다.

public class MyApplication extends MultiDexApplication { ... }

Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:

public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}

3) Add multidex support to defaultConfig at build.gradle

defaultConfig {
        ...
        minSdkVersion 16
        targetSdkVersion 26
        ...
        // Enabling multidex support.
        multiDexEnabled true
    }
...

Before messing around with MultiDex

It either solution is too big (use MultiDex) or you compile and include in your project some not needed stuff. I got this issue on my tiny project. Here is what I did to fix it:

I removed this from build.gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

And I manually removed my build folder from application root. Problem fixed.


Follow this guide to workaround 65K limit.

I solved this issue in gradle by setting multiDexEnabled true and extending my application with class MyApp extends MultiDexApplication


I simply commented out the compile filetree(include: ['*.jar'], dir: 'libs') in the build.gradle file (as suggested above) and rebuilt the project. Compiled without any errors. I did not need to move any folders.


First make sure that minification is enabled in app/build.cradle:

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.config
    }
    debug {
        signingConfig signingConfigs.config
    }
}

If this does not solve the issue, enable multidex build for your app.


I faced this issue when i had compiled the entire package of Google Play Services APIs into my app. I solved the issue by using selective API.

For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:

compile 'com.google.android.gms:play-services:11.0.2'

with these lines:

compile 'com.google.android.gms:play-services-fitness:11.0.2'
compile 'com.google.android.gms:play-services-wearable:11.0.2'

Issue is explained in following link.

참고URL : https://stackoverflow.com/questions/26515378/dexindexoverflowexception-issue-after-updating-to-latest-appcompat-and-support-l

반응형