On this page14 sections
  1. Prerequisites
  2. Learning Objectives
  3. 1. settings.gradle.kts: Declare the Plugin
  4. 2. app/build.gradle.kts: Apply It
  5. 3. SDK Versions
  6. 4. You Don't Need the Native Dependencies
  7. 5. The Manifest
  8. Code Examples
  9. Common Beginner Mistakes
  10. Best Practices
  11. Practice Questions
  12. Practice Answers
  13. Key Takeaways
  14. Full Code (Copy-Paste Reference)

Lecture 002: Android Gradle & Manifest Setup

Category1: Firebase Setup
Lecture002 of 014
Estimated video length16 min
TargetFlutter 3.44 · Dart 3.12 · FlutterFire (latest)
LevelIntermediate

google-services.json is in place, but Android doesn't read it by itself. The Google services Gradle plugin does. We add it, set the SDK versions Firebase needs, and check the manifest.

Contents

Prerequisites · Objectives · Lesson · Code Examples · Common Mistakes · Best Practices · Practice Questions · Answers · Takeaways · Full Code


Prerequisites

Lecture 001: google-services.json in android/app/.


Learning Objectives

  • Declare the Google services plugin in settings.gradle.kts
  • Apply it in the app-level build.gradle.kts
  • Set minSdk, targetSdk and compileSdk
  • Know which old setup steps you no longer need
  • Add the manifest permissions

1. settings.gradle.kts: Declare the Plugin

New Flutter projects use Kotlin Gradle files (.kts). Open android/settings.gradle.kts and add one line to the plugins block:

kotlin
plugins {
    id("dev.flutter.flutter-plugin-loader") version "1.0.0"
    id("com.android.application") version "9.0.1" apply false
    id("org.jetbrains.kotlin.android") version "2.3.20" apply false
    id("com.google.gms.google-services") version "4.5.0" apply false   // ← add
}

apply false means: make the plugin available, don't use it here. Keep the versions of the other lines as your project has them.

Older guides tell you to add classpath 'com.google.gms:google-services:4.3.15' to the project-level build.gradle. That is the old way, replaced by the plugins block above: don't add both.

2. app/build.gradle.kts: Apply It

Open android/app/build.gradle.kts:

kotlin
plugins {
    id("com.android.application")
    id("dev.flutter.flutter-gradle-plugin")
    id("com.google.gms.google-services")   // ← add
}

The plugin reads google-services.json and turns it into Android resources at build time.

3. SDK Versions

In the same file:

kotlin
android {
    compileSdk = flutter.compileSdkVersion

    defaultConfig {
        applicationId = "com.example.notify_demo"
        minSdk = 24                              // ← was flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        // ...
    }
}

flutter.compileSdkVersion and flutter.targetSdkVersion follow your Flutter version (36 at the time of writing): keep them. Only minSdk needs a fixed number.

SettingMeaning
compileSdkthe Android version your code is compiled against
targetSdkthe Android version your app is tested for (Play requires a recent one)
minSdkthe oldest Android version that can install the app

Current FlutterFire packages need minSdk 24 or higher. Older notes say 21: that was enough for old Firebase versions only.

4. You Don't Need the Native Dependencies

Firebase's Android guide tells you to add a dependencies { implementation(platform( "com.google.firebase:firebase-bom:...")) ... } block. In Flutter, skip it. Each FlutterFire package (firebase_messaging, firebase_analytics, …) brings its own matching native library. Adding them by hand only risks version clashes.

5. The Manifest

Open android/app/src/main/AndroidManifest.xml. Firebase needs the internet:

xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.INTERNET"/>
    <!-- Android 13+: lets the app ask to show notifications (Lecture 005) -->
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

    <application
        android:label="notify_demo"
        android:icon="@mipmap/ic_launcher">
        <!-- ... -->
    </application>
</manifest>

android:usesCleartextTraffic="true" on <application> allows plain http:// connections. Firebase always uses HTTPS, so it isn't needed for Firebase: add it only if your app also talks to an http:// server, such as a local test API.


Code Examples

Example 1: Check the Build

bash
flutter clean
flutter pub get
flutter run

If the app starts on the emulator as before, Gradle found the plugin and read google-services.json. Nothing visible changes yet: Lecture 004 connects the Dart side.


Common Beginner Mistakes

1. Groovy syntax in a .kts file: id 'com.google.gms.google-services' works only in build.gradle. In build.gradle.kts write id("com.google.gms.google-services").

2. Plugin applied but not declared: "Plugin with id 'com.google.gms.google-services' not found" means the settings.gradle.kts line is missing.

3. minSdk too low: "uses-sdk:minSdkVersion 21 cannot be smaller than version 24 declared in library". Raise minSdk.


Best Practices

  • Use the plugins { } blocks; don't mix in old buildscript { classpath ... } lines.
  • Let FlutterFire packages manage native Firebase libraries.
  • Run flutter clean after changing Gradle files if the build behaves strangely.

Practice Questions

  1. Which file declares the Google services plugin, and which one applies it?
  2. What does apply false mean?
  3. Why don't Flutter apps need the Firebase BoM dependency block?
  4. Is usesCleartextTraffic needed for Firebase?

Practice Answers

  1. android/settings.gradle.kts declares it; android/app/build.gradle.kts applies it.
  2. The plugin is made available but not used in that file.
  3. Each FlutterFire package adds the matching native Firebase library itself.
  4. No: Firebase uses HTTPS. It's only for plain http:// servers.

Key Takeaways

  • Declare com.google.gms.google-services in settings.gradle.kts, apply it in the app file.
  • Firebase needs minSdk 24+; keep targetSdk/compileSdk from Flutter.
  • Skip native firebase-bom dependencies in Flutter.
  • The manifest needs INTERNET (and POST_NOTIFICATIONS for notifications).

Full Code (Copy-Paste Reference)

No Dart code yet: everything this lecture touches is Gradle/manifest config.

android/settings.gradle.kts (relevant part)

kotlin
plugins {
    id("dev.flutter.flutter-plugin-loader") version "1.0.0"
    id("com.android.application") version "9.0.1" apply false
    id("org.jetbrains.kotlin.android") version "2.3.20" apply false
    id("com.google.gms.google-services") version "4.5.0" apply false // declared here
}

android/app/build.gradle.kts (relevant parts)

kotlin
plugins {
    id("com.android.application")
    id("dev.flutter.flutter-gradle-plugin")
    id("com.google.gms.google-services") // applied here - reads google-services.json
}

android {
    compileSdk = flutter.compileSdkVersion

    defaultConfig {
        applicationId = "com.example.notify_demo"
        minSdk = 24 // Firebase needs 24+; was flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        // ...
    }
}

android/app/src/main/AndroidManifest.xml (relevant part)

xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.INTERNET"/>
    <!-- Android 13+: lets the app ask to show notifications (Lecture 005) -->
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

    <application
        android:label="notify_demo"
        android:icon="@mipmap/ic_launcher">
        <!-- ... -->
    </application>
</manifest>