FAILURE: Build failed with an exception.|flutter
flutterでデバッグしていたらさっきまで問題なかったのに、急に下記のようなエラーがでました。
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
このエラーは、アプリのメソッド参照数が64Kの制限を超えたことを示しています。
この問題を解決するには、マルチデックスを有効にする必要があります。
という意味らしいので、下記を施してみる。
1、android/app/build.gradle ファイルを編集します。
android {
defaultConfig {
...
multiDexEnabled true
}
...
}
2依存関係にマルチデックスライブラリを追加します。同じ build.gradle ファイルの依存関係セクションに以下を追加します。
dependencies {
implementation 'com.android.support:multidex:1.0.3'
...
}
3、android/app/main/AndroidManifest.xml ファイルを編集します。
<application
android:name="androidx.multidex.MultiDexApplication"
... >
...
</application>
以上、正常にエミュレーターが起動してデバッグできました。

