On this page14 sections
- Prerequisites
- Learning Objectives
- 1. settings.gradle.kts: Declare the Plugin
- 2. app/build.gradle.kts: Apply It
- 3. SDK Versions
- 4. You Don't Need the Native Dependencies
- 5. The Manifest
- Code Examples
- Common Beginner Mistakes
- Best Practices
- Practice Questions
- Practice Answers
- Key Takeaways
- Full Code (Copy-Paste Reference)
Lecture 002: Android Gradle & Manifest Setup
| Category | 1: Firebase Setup |
| Lecture | 002 of 014 |
| Estimated video length | 16 min |
| Target | Flutter 3.44 · Dart 3.12 · FlutterFire (latest) |
| Level | Intermediate |
google-services.jsonis 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,targetSdkandcompileSdk - 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:
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-levelbuild.gradle. That is the old way, replaced by thepluginsblock above: don't add both.
2. app/build.gradle.kts: Apply It
Open android/app/build.gradle.kts:
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:
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.
| Setting | Meaning |
|---|---|
compileSdk | the Android version your code is compiled against |
targetSdk | the Android version your app is tested for (Play requires a recent one) |
minSdk | the 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:
<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 plainhttp://connections. Firebase always uses HTTPS, so it isn't needed for Firebase: add it only if your app also talks to anhttp://server, such as a local test API.
Code Examples
Example 1: Check the Build
flutter clean
flutter pub get
flutter runIf 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 oldbuildscript { classpath ... }lines. - Let FlutterFire packages manage native Firebase libraries.
- Run
flutter cleanafter changing Gradle files if the build behaves strangely.
Practice Questions
- Which file declares the Google services plugin, and which one applies it?
- What does
apply falsemean? - Why don't Flutter apps need the Firebase BoM dependency block?
- Is
usesCleartextTrafficneeded for Firebase?
Practice Answers
android/settings.gradle.ktsdeclares it;android/app/build.gradle.ktsapplies it.- The plugin is made available but not used in that file.
- Each FlutterFire package adds the matching native Firebase library itself.
- No: Firebase uses HTTPS. It's only for plain
http://servers.
Key Takeaways
- Declare
com.google.gms.google-servicesinsettings.gradle.kts, apply it in the app file. - Firebase needs
minSdk24+; keeptargetSdk/compileSdkfrom Flutter. - Skip native
firebase-bomdependencies in Flutter. - The manifest needs
INTERNET(andPOST_NOTIFICATIONSfor notifications).
Full Code (Copy-Paste Reference)
No Dart code yet: everything this lecture touches is Gradle/manifest config.
android/settings.gradle.kts (relevant part)
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)
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)
<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>