In my flutter application i am using firebase_auth for google_sign_in and it is working fine. But when i add cloud_firestore: to pubspec.yaml then get dependencies and then restart my app it show me an error like this:
FAILURE: Build failed with an exception.
* What went wrong:
The library com.google.android.gms:play-services-base is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.0.1. 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.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
Finished with error: Gradle build failed: 1
I have used this dependencies in my android/build.gradle file
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.1'
and used this version for firebase and google in pubspec.yaml
firebase_auth: 0.5.11
google_sign_in: 3.0.4
cloud_firestore: 0.7.3
It works fine because at these versions gradle tooling was updated to match Android Studio 3.1.2.
Other firebase working versions:
firebase_admob: 0.5.5
firebase_analytic: 1.0.1
firebase_core: 0.2.4
firebase_database: 1.0.1
firebase_dynamic_links: 0.02
firebase_messaging: 1.0.2
firebase_performance: 0.0.3
firebase_remote_config: 0.0.4
firebase_storage: 0.3.7
This link solved the issue for me.
First I set dependencies in my pubspec.yaml to
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.8.2
and ran flutter packages get
in my IDE's terminal.
Also I had to change the minimum target SDK version:
- Open
android/app/build.gradle
, then find the line that saysminSdkVersion 16
. - Change that line to
minSdkVersion 21
. - Save the file.
Also, I had to open android/app/build.gradle
, then add the following line as the last line in the file:
apply plugin: 'com.google.gms.google-services'
Next, I had to open android/build.gradle
, then inside the buildscript tag, add a new dependency:
buildscript {
repositories {
// ...
}
dependencies {
// ...
classpath 'com.google.gms:google-services:3.2.1' // new
}
}
After this my app finally ran on the android emulator.
The link has a more complete walkthrough if you get stuck.
来源:https://stackoverflow.com/questions/52756049/gradle-issue-in-flutter-when-using-firebase