DEV Community

caelinsutch
caelinsutch

Posted on • Updated on

Setting up your Flutter app with Firebase

Lets create a Flutter app and get it all setup with Firebase.

Create your Flutter App

Create your app and open it in your IDE of choice.

flutter create my_app

Install Dependencies

Below are the dependneices for Firebase in Flutter, assuming you're using Firestore and Google Signin.

dependencies:
  flutter:
    sdk: flutter

  firebase_core: ^0.4.0
  firebase_analytics: ^1.0.4

  cloud_firestore: ^0.8.2+3

  firebase_auth:  ^0.6.6
  google_sign_in: ^3.2.4

Setup Firebase

Android Setup

Generate your SHA Certificates

Make sure you have Java installed. On Ubuntu, you can install it by running sudo apt-get install default-jdk.

Open up your terminal at the Flutter project root, and run cd android to mvoe into the android directory. Then run ./gradlew signingReport to generate the SHA1 and SHA256 keys. Copy and paste them from the Varient: debug section

Make sure you know your application ID, this can be found in the android/app/build.gradle file under your defaultConfig. Grab that for the next step.

Create your Firebase Project

Create your Firebase Project

Go to the Firebase console and create your new project. Register your app by clicking Add Firebase to your Android app. Enter your project ID, package name,. and the SHA-1 Certificate from the last step. Download the google-services.json file to the android/app directory.

Android Setup Page

Now click through the rest of the setup, and go into your project settings. In the general tab, you'll see a section called "Your apps". Click the "Add fingerprint" section and copy and paste the SHA256 key from the last step, then redownload the config file.

Update the build.gradle files

Lets register the Google Services in the Gradle build files for Android.

Lets start with the one in android/build.gradle


buildscript {
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
  }
  dependencies {
    ...
    // Add this line
    classpath 'com.google.gms:google-services:4.3.2'
  }
}

allprojects {
  ...
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
    ...
  }
}

And then the android/app/build.gradle

 apply plugin: 'com.android.application'

dependencies {
  // add the Firebase SDK for Google Analytics
  implementation 'com.google.firebase:firebase-analytics:17.2.0'
  // add SDKs for any other desired Firebase products
  // https://firebase.google.com/docs/android/setup#available-libraries
}
...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

That's it! Try running it with an Android emulator or device to verify everything worked.

iOS Setup

The iOS setup is less tedious and can be completed in one step.

IOS setup

Register and Download the GoogleService-Info.plist

Click add your app to iOS then download the GoogleService-Info.plist file into the ios/Runner/Runner directory from XCode. Make sure that your application ID matches in registration and in XCode.

Top comments (8)

Collapse
 
kdheeraj280702 profile image
Kdheeraj280702

After doing all the stuff Iam getting a error that Firebase_core_not found

Collapse
 
caelinsutch profile image
caelinsutch

Did you run ‘flutter pub get’?

Collapse
 
kdheeraj280702 profile image
Kdheeraj280702

Yes! I’ve tried it

Thread Thread
 
kdheeraj280702 profile image
Kdheeraj280702

And when I build the app it’s showing the error can’t find what’s the issue

Thread Thread
 
caelinsutch profile image
caelinsutch

This is on Android?

Thread Thread
 
kdheeraj280702 profile image
Kdheeraj280702

Yes

Collapse
 
caelinsutch profile image
caelinsutch

I just updated the post, try those instructions

Collapse
 
kdheeraj280702 profile image
Kdheeraj280702

What part shld I change