4

Adding cloud_firestore: ^0.12.10 dependency in my flutter project gives errors.

These are the dependencies my project has:

dependencies:
  url_launcher: ^5.0.0
  flutter_launcher_icons: ^0.7.4

  cloud_firestore: ^0.12.10

  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  firebase_messaging: ^5.1.6

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter_icons:
  android: "launcher_icon"
  ios: true
  image_path: "assets/launcher_icon/LauncherIcon.png"

I tried to use different cloud_firestore versions, but none of them worked.

This is the output of flutter run command in the terminal:

Launching lib\main.dart on SM A505F in debug mode...
Initializing gradle...                                              1.1s
Resolving dependencies...                                          16.3s
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

FAILURE: Build failed with an exception.

* What went wrong:
Failed to notify dependency resolution listener.
> The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[17.2.1,17.2.1]], but resolves to 16.5.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
> The library com.google.firebase:firebase-iid is being requested by various other libraries at [[20.0.0,20.0.0]], but resolves to 17.1.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

* 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 11s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                        11.8s
Gradle task assembleDebug failed with exit code 1

This is the output of flutter doctor -v:

[√] Flutter (Channel stable, v1.9.1+hotfix.6, on Microsoft Windows [Version 10.0.18362.418], locale en-IN)
    • Flutter version 1.9.1+hotfix.6 at D:\flutter_windows_v1.9.1+hotfix.2-stable\flutter
    • Framework revision 68587a0916 (8 weeks ago), 2019-09-13 19:46:58 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0


[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at C:\Users\aditl\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[√] Android Studio (version 3.5)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 41.0.2
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.40.0)
    • VS Code at C:\Users\aditl\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.6.0

[√] Connected device (1 available)
    • SM A505F • RZ8M60LFVPP • android-arm64 • Android 9 (API 28)

! Doctor found issues in 1 category.
Adit Luhadia
  • 414
  • 8
  • 18

3 Answers3

3

from you log errors

* What went wrong:
Failed to notify dependency resolution listener.
> The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[17.2.1,17.2.1]], but resolves to 16.5.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
> The library com.google.firebase:firebase-iid is being requested by various other libraries at [[20.0.0,20.0.0]], but resolves to 17.1.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

you need to update firebase core to 17.2.1 if you have added it to your gradle files,

Although this is an issue with your project not being androidX enabled see how to migrate to androidX

update

    Cannot fit requested classes in a single dex file (# methods: 81876 > 65536)
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

you need to enable multidex for your application as follows

    android {
    defaultConfig {
        ...
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}

dependencies {
  implementation "androidx.multidex:multidex:2.0.0"
}
griffins
  • 7,079
  • 4
  • 29
  • 54
  • 1
    I followed the steps given on the page, but I got a `No usages found in the project` error. So, I followed [this answer](https://stackoverflow.com/a/54857699/7608627) to manually migrate to AndroidX. I updated all the dependencies to their latest versions. Everything was working fine without the cloud_firestore dependency. When I added the `cloud_firestore: ^0.12.10` dependency, I got [this error](https://pastebin.com/3nU2eFgu). – Adit Luhadia Nov 10 '19 at 19:55
  • 1
    @MasterAdit i updated my answer to fit multidex,also if you didnt add firestore correctly to your app consider checking this out https://firebase.google.com/docs/flutter/setup – griffins Nov 11 '19 at 02:08
2

Add this line of code in your android/build.gradle file in the bottom. I think you missed the step of adding the services plugin. Try this

and put cloud_firestore: ^0.12.10 dependency below firebase_messaging dependency.

Code:

apply plugin: 'com.google.gms.google-services'
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Nadir
  • 61
  • 5
  • 1
    I added `cloud_firestore: ^0.12.10` below `firebase_messaging`, but I am still getting an error. I already have `apply plugin: 'com.google.gms.google-services'` in `android/app/build.gradle` file (not in `android/build.gradle`). I also tried adding `apply plugin: 'com.google.gms.google-services'` to `android/build.gradle`, but it gave me a different error. – Adit Luhadia Nov 10 '19 at 06:24
-1

Add this line inside your target 'Runner' do block in your Podfile, e.g.:

# ...
target 'Runner' do
  pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '8.9.0'
# ...
end
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Mesfin T
  • 1
  • 1
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Dec 26 '21 at 08:23