This is highly dependent on what version of Firebase SDK you use.
pubspec.yaml
simple_firebase\pubspec.yaml
dependencies:
flutter:
sdk: flutter
firebase_core: "^0.5.0"
# Add the dependency for the FlutterFire plugin for Google Analytics
firebase_analytics: ^6.0.0
# Add the dependencies for any other Firebase products you want to use in your app
# For example, to use Firebase Authentication and Cloud Firestore
#firebase_auth: ^0.18.0+1
cloud_firestore: ^0.14.0+2
android\gradle\wrapper\gradle-wrapper.properties
Change
#distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
Or you will may this error later
Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
Edit both the project and app build gradles
simple_firebase\android\build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Add the following line:
classpath 'com.google.gms:google-services:4.3.3' // Google Services plugin
}
simple_firebase\android\app\build.gradle
Add the following
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
//Add the following line
apply plugin: 'com.google.gms.google-services' // Google Services plugin
Update you minSDK
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.simple_firebase"
#minSdkVersion 16
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Remember you applicationID because you will need it when you register your app with Firebase
Register app with Firebase
Add google-services.json
simple_firebase\android\app\google-services.json
OF you will get the folliwing error File google-services.json is missing. The Google Services Plugin cannot function without it.
Commands
./gradlew build
- Log in to post comments