Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execution failed for task ':app:mergeDexDebug'. Firestore | Flutter

Trying to use Firestore in my project. My project is a brand new one, but having problems running the app on my device without getting an error: Execution failed for task ':app:mergeDexDebug'.

My app is using AndroidX. I've added my google-services.json file, followed the steps etc.

Yaml file:

dependencies:
  cloud_firestore: ^0.13.3

android/build.gradle:

com.google.gms:google-services:4.3.3

Full error:

FAILURE: Build failed with an exception.

What went wrong: Execution failed for task ':app:mergeDexDebug'. A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade 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

like image 380
Jonathon Avatar asked Feb 19 '20 23:02

Jonathon


2 Answers

The problem is with multidex builder. Actually, this often happens when you have imported a lot of packages in your yaml file which cannot fit into a single .dex built hence you have to enable multidex.

Go to android/app/build.gradle and add the following lines of codes:

dependencies {
  implementation 'com.android.support:multidex:2.0.1' //enter the latest multidex version
}
android {
    defaultConfig {
        multiDexEnabled true
    }
}
like image 99
lordvidex Avatar answered Nov 08 '22 10:11

lordvidex


Fixed the issue, but don't understand why. Why do I need to enable multiDex when I believe Firestore is using AndroidX?

Anyway, the fix. Add multiDexEnabled true to your app/build.gradle

defaultConfig {
    // TODO: Specify your own unique Application ID 
    (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.poll"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    //This line here...
    multiDexEnabled true
}
like image 22
Jonathon Avatar answered Nov 08 '22 12:11

Jonathon