새소식

반응형
App/Android

[Android] dex file 과 multiDexEnabled 알아보기 (Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: XXXXXX > 65536 해결)

  • -
반응형

2023-11-30


사진: Unsplash 의 Kate Laine


1. 이슈 발생

 

Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: XXXXXX > 65536

 

 

위와 같은 이슈가 발생하였는데 오류의 내용은 하나의 dex file은 65536을 넘길 수 없으니 당신의 앱이 main-dex list를 허용하라는 이슈이다. 우선 dex file이 뭔지 알아보자.


2. dex file?

 

Android 애플리케이션(APK) 파일에는 DEX(Dalvik Executable) 파일 형식의 실행 가능한 바이트코드 파일이 포함되어 있으며, 여기에는 앱을 실행하는 데 사용되는 컴파일된 코드가 포함되어 있다. 즉 자신의 앱을 실행시키기 위한 바이트코드 덩어리라고 볼 수 있다. 또한 해당 dex 파일 하나당 65536개의 메서드만 정의될 수 있어 해당 부분이 초과될 경우 multiDexEnabled  옵션을 true 값으로 변경하여 여러 개의 dex 파일을 운영 가능하게 해야 한다.


3. 해결 방법

 

해결 방법은 간단하다. 아래의  build.gradle  참고 코드와 같이 자신의 안드로이드 앱 build.gradle 에 defaultConfig 쪽에 multiDexEnabled true를 선언하고 dependencies 에는 implementation 'com.android.support:multidex:1.0.3' 선언하면 된다.

 

android {
    namespace "com.example.vapps"
    // compileSdkVersion flutter.compileSdkVersion
    compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
		// your defaultConfig
        //. . . .
        multiDexEnabled true
    }

    buildTypes {
        release {
		// your buildTypes
        //. . . .
        }
    }
}

// . . .

dependencies {
     implementation 'com.android.support:multidex:1.0.3'
}

4. 참고링크

https://stackoverflow.com/questions/36856068/what-does-multidexenabled-true-mean

 

What does "multiDexEnabled true" mean?

What is meant by "multiDexEnabled true" in Android gradle. Why do we use this? What is the effect if it is enabled?

stackoverflow.com

https://stackoverflow.com/questions/48249633/errorcannot-fit-requested-classes-in-a-single-dex-file-try-supplying-a-main-dex

 

Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536

I want to add fused location services but it shows me some error. Help me. apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "27.0.1"

stackoverflow.com


메인 이미지 출처 : 사진: UnsplashKate Laine

반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.