Skip to main content

Android Installation

Notice

This page is archived and might not reflect the latest version of the FlutterFire plugins. With the latest plugins, manual installation is not required. You can find the latest information on firebase.google.com:

https://firebase.google.com/docs/flutter/setup

Before using FlutterFire on Android, you must first connect to your Firebase project with your Android application.

Generating a Firebase project configuration file#

On the Firebase Console, add a new Android app or select an existing Android app for your Firebase project.

The "Android package name" must match your local project's package name that was created when you started the Flutter project. The current package name can be found in your module (app-level) Gradle file, usually android/app/build.gradle, defaultConfig section (example package name: com.yourcompany.yourproject).

When creating a new Android app "debug signing certificate SHA-1" is optional, however, it is required for Dynamic Links & Phone Authentication. To generate a certificate run cd android && ./gradlew signingReport and copy the SHA1 from the debug key. This generates two variant keys. You can copy the 'SHA1' that belongs to the debugAndroidTest variant key option.

Once your Android app has been registered, download the configuration file from the Firebase Console (the file is called google-services.json). Add this file into the android/app directory within your Flutter project.

Installing your Firebase configuration file#

To allow Firebase to use the configuration on Android, the 'google-services' plugin must be applied on the project. This requires modification to two files in the android/ directory.

First, add the 'google-services' plugin as a dependency inside of the android/build.gradle file:

android/build.gradle
buildscript {
dependencies {
// ... other dependencies
classpath 'com.google.gms:google-services:4.3.8'
}
}

Lastly, execute the plugin by adding the following underneath the line apply plugin: 'com.android.application', within the /android/app/build.gradle file:

android/app/build.gradle
apply plugin: 'com.google.gms.google-services'

Building for Android#

Due to the large number of classes in some of the Firebase SDKs (specifically Firestore), it may bump you over the 64k method limit on the Android build system and you may get an error stating Error while merging dex archives: The number of method references in a .dex file cannot exceed 64K.

If you do get this error, we suggest enabling Multidex for Android.

Enabling Multidex#

If your app only targets Android 21 or higher (minSdkVersion) then multidex is already enabled by default and you do not need the multidex support library.

However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library and make the following modifications to your app project:

Open the /android/app/build.gradle file. Under dependencies add the multidex module, and enable it within the defaultConfig:

android {
defaultConfig {
// ...
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}

Visit the official Android documentation to learn more.

Enabling use of Firebase Emulator Suite#

The Firebase Emulator Suite uses un-encrypted networking connections in order to enable fast, uncomplicated setup. However Android by default requires encrypted networking connections. If you would like to use any part of the Firebase Emulator Suite to emulate firebase services on your local machine during development, you must allow your Android app to connect to local network services over insecure connections.

To allow insecure connections, we recommend adding the usesCleartextTraffic=true attribute to the application element of AndroidManifest.xml in the debug configuration tree, so you do not accidentally allow unencrypted traffic in release builds.

Specifically in your app, edit (or create the file if necessary) android/app/src/debug/AndroidManifest.xml:

<application android:usesCleartextTraffic="true">
<!-- possibly other elements -->
</application>