Search code examples
fluttergoogle-cloud-firestorebarcode-scanner

Flutter: Cloud_firestore will break your Android build if it or its dependencies aren't compatible with AndroidX


I can not use these both flutter plugins together:

  cloud_firestore: ^0.9.0+2
  barcode_scan: ^0.0.8

When run, error occured:

D8: Program type already present: android.arch.core.util.Function
     *********************************************************
WARNING: This version of cloud_firestore will break your Android build if it or its dependencies aren't compatible with AndroidX.
         See https: //goo.gl /CP92wY for more information on the problem and how to fix it.
         This warning prints for all Android build failures. The real root cause of the error may be unrelated.
         *********************************************************

FAILURE: Build failed with an exception.

it compiled and runned on Android phone when I remove one of them. But both can not go together. How to fix?


Solution

  • In short

    Add multidex library to android app dependency (/android/app/build.gradle)

    ...
    android {
      ...
      defaultConfig {
        ...
        multiDexEnabled true
      }
      ...
    }
    ...
    dependencies {
      implementation 'com.android.support:multidex:1.0.3' // use latest version
      ...
    }
    ...
    

    under android directory gradel.properties file

    Add

    android.useAndroidX=true
    android.enableJetifier=true