FAILURE: Build failed with an exception.|flutter
flutterでデバッグしていたらさっきまで問題なかったのに、急に下記のようなエラーがでました。
1 2 3 4 5 6 7 8 9 10 | 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 ファイルを編集します。
1 2 3 4 5 6 7 | android { defaultConfig { ... multiDexEnabled true } ... } |
2依存関係にマルチデックスライブラリを追加します。同じ build.gradle ファイルの依存関係セクションに以下を追加します。
1 2 3 4 | dependencies { implementation 'com.android.support:multidex:1.0.3' ... } |
3、android/app/main/AndroidManifest.xml ファイルを編集します。
1 2 3 4 5 | <application android:name= "androidx.multidex.MultiDexApplication" ... > ... </application> |
以上、正常にエミュレーターが起動してデバッグできました。