본문 바로가기
개발

Flutter에서 Android 빌드시 multidex 설정법

by GreatCoding 2023. 3. 14.

Flutter로 개발한 앱을 Android에서 빌드 할 경우  메쏘드가 64k를 초과했다며 multidex 사용 설정을 하라는 아래와 같은 메시지를 만날때가 있다.

 

앱 빌드시 다음과 같은 에러메시지가 나타난다

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 44s
[!] App requires Multidex support
    Multidex support is required for your android app to build since the number of methods has exceeded 64k.
    See https://docs.flutter.dev/deployment/android#enabling-multidex-support for more information.
    You may pass the --no-multidex flag to skip Flutter's multidex support to use a manual solution.

    Flutter tool can add multidex support. The following file will be added by flutter:

        android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java

cannot prompt without a terminal ui
Exception: Gradle task assembleDebug failed with exit code 1

 

Flutter Multidex 에러 해결 방법

이럴땐 android/app/build.gradle 파일에서 아래와 같이

defaultConfig안에 multiDexEnabled true 를,
dependencies안에 implementation "com.android.support:multidex:2.0.1" 를 추가해주면 된다.

...
android {
...
    defaultConfig {
        ...
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true // 이 줄을 추가!!!
    }
...
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "com.android.support:multidex:2.0.1" // 이 줄을 추가!!!
}

 

이와 같이 Flutter로 안드로이드 빌드할때 만날 수 있는 multidex 에러를 해결하는 방법에 대해서 알아봤습니다.

댓글