Flutter & Firebase - Flutter multidex handling is disabled 오류 해결 방법

2022. 7. 15. 14:28DEV/Flutter

반응형

Flutter multidex handling is disabled. If you wish to let the tool configure multidex, use the --multidex flag.

Firebase 라이브러리 설치 후 Android Emulator에 프로젝트를 실행하면 발생하는 Multidex Exception을 해결해보자.

ERROR:D8: Cannot fit requested classes in a single dex file (# methods: 92002 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
...
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: null
...
Caused by: com.android.tools.r8.internal.b: Cannot fit requested classes in a single dex file (# methods: 92002 > 65536)
...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingTaskDelegate
   > There was a failure while executing work items
      > A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingWorkAction
         > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
           The number of method references in a .dex file cannot exceed 64K.
           Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3m 11s
[!] App requires Multidex support
┌─ Flutter Fix ──────────────────────────────────────────────────────────────────────────────────┐
│ Flutter multidex handling is disabled. If you wish to let the tool configure multidex, use the │
│ --multidex flag.                                                                               │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
Exception: Gradle task assembleDebug failed with exit code 1
Exited

/android/app/build.gradle

  1. android > defaultConfig에 multiDexEnabled 설정을 true로 추가한다.
  2. dependencies에 multidex implementation을 추가한다.
android {
    ...
    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.mychat"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        // minSdkVersion flutter.minSdkVersion // * 기본 설정
        minSdkVersion 19 
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        // ------ MultiDex 설정 추가 ------> //
        multiDexEnabled true
        // <------ MultiDex 설정 추가 ------ //
    }
}
...
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    // ------ MultiDex 설정 추가 ------> //
    implementation 'com.android.support:multidex:2.0.1'
    // <------ MultiDex 설정 추가 ------ //
}

프로젝트를 다시 실행하면 정상적으로 작동이 된다.

 

반응형