Integration Firebase in Android Studio opens up powerful tools for developers to create modern mobile applications. This service from Google offers ready-made solutions for working with a real-time database, user authentication, analytics, cloud storage and much more - all without the need to deploy your own backend. However, the connection process often raises questions for beginners: where to get the configuration file, how to add dependencies correctly, and why the project does not compile after integration?

In this article we will analyze step-by-step algorithm adding Firebase in Android Studio taking into account the latest versions of tools (2026). We will pay special attention to typical errors that arise during setup and ways to solve them. You will learn not only how to connect basic services, but also how to optimize work with Firebase Realtime Database, Authentication i Cloud Messaging. The material will be useful for both novice developers and experienced professionals who want to systematize their knowledge.

1. Preparing a project in Android Studio

Before connecting Firebase, you need to make sure that your project is in Android Studio meets the minimum requirements. First, check the version compileSdkVersion i targetSdkVersion in the file build.gradle (Module: app). For stable work with Firebase it is recommended to use API level 21 (Android 5.0 Lollipop) or higher. Secondly, update to the latest stable version. This is important because new versions API level 21 (Android 5.0 Lollipop) or higher.

Secondly, update Android Studio to the latest stable version. This is important because new versions Firebase may require up-to-date build tools. For example, if you use Firebase BoM (Bill of Materials) to version control libraries, an outdated development environment may cause dependency conflicts.

  • ๐Ÿ“Œ Check the version Gradle Plugin in file build.gradle (Project). It should be no lower 7.0.0.
  • ๐Ÿ”„ Update Google Play services via SDK Manager (menu Tools โ†’ SDK Manager โ†’ SDK Tools).
  • ๐Ÿ“‚ Make sure that the project does not have conflicting libraries (for example, old versions Firebase Core).
โš ๏ธ Attention: If your project uses Kotlin, add the plugin kotlin-android to build.gradle (Project). Without it, some Firebaselibraries may not compile correctly.

It is also recommended to create a backup copy of the project before starting the integration. quickly rollback in case of critical errors. To do this, just copy the project folder or use a version control system (Git).

๐Ÿ“Š Which Firebase service are you planning to use?
Authentication
Database (Realtime Database)
Cloud messages (FCM)
Analytics
Storage

2. Registering a project in the Firebase Console

To connect Firebase to Android application, you first need to register it in Firebase ConsoleGo to the site Firebase Console and log in through your account Google. Click the button "Add project" and follow the instructions:

  1. Enter the name of the project (may be the same as the name of your application).
  2. Disable Google Analyticsif you do not plan to use it (this is optional step).
  3. After creating the project, click on the icon Android (๐Ÿ“ฑ) to add an application.

At the next stage, the system will ask you to enter your application package name (for example, com.example.myapp). This value must exactly match applicationId in the file build.gradle (Module: app). You will also need to specify signing certificate fingerprint (SHA-1). It can be obtained via the command line:

keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
  • ๐Ÿ” If you are using a release key, replace the path to debug.keystore with your file.
  • ๐Ÿ“‹ Copy the SHA-1 fingerprint and paste it into Firebase Console.
  • ๐Ÿ“ฅ After registration, download the file google-services.json โ€”you will need it to set up the project.
โš ๏ธ Attention: If you are testing the application on several devices or using different builds (for example, debug and release), add all relevant SHA-1 fingerprints to the project settings Firebase. Otherwise, authentication and other services may not work.

3. Adding Firebase SDK to the project

After registering the application in Firebase Console you need to integrate Firebase SDK into your project. Start by moving the file google-services.json to your project folder (at the same level as app your project (on the same level as build.gradle). Then open the file build.gradle (Project) and add the dependency for Google Services:

buildscript {

dependencies {

// Add this line

classpath 'com.google.gms:google-services:4.3.15'

}

}

Next, open the file build.gradle (Module: app) and add two lines:

  1. At the very bottom of the file: apply plugin: 'com.google.gms.google-services'
  2. In the block dependencies add Firebase BoM (to control versions) and required libraries:
dependencies {

// Firebase BoM (optional, but recommended)

implementation platform('com.google.firebase:firebase-bom:32.7.0')

// Add the required Firebase products

implementation 'com.google.firebase:firebase-analytics-ktx'

implementation 'com.google.firebase:firebase-auth-ktx'

implementation 'com.google.firebase:firebase-database-ktx'

}

Firebase Library Purpose Minimum dependency
firebase-analytics-ktx Collection of application usage statistics implementation 'com.google.firebase:firebase-analytics-ktx'
firebase-auth-ktx User authentication (email, Google, Facebook, etc.) implementation 'com.google.firebase:firebase-auth-ktx'
firebase-database-ktx Working with Realtime Database implementation 'com.google.firebase:firebase-database-ktx'
firebase-storage-ktx Cloud file storage implementation 'com.google.firebase:firebase-storage-ktx'

After adding dependencies, synchronize the project s Gradle (button "Sync Now" in the upper right corner Android Studio). If synchronization errors occur, check:

  • ๐Ÿ”Œ Correct Internet connection (sometimes Gradle cannot download dependencies).
  • ๐Ÿ“ No typos in build.gradle.
  • ๐Ÿ› ๏ธ Compatibility of library versions (if you use BoM, conflicts are unlikely).

โ˜‘๏ธ Check before synchronizing Gradle

Completed: 0 / 4

4. Initializing Firebase in the application

After successful synchronization Gradle you can begin initialization Firebase in the application code. In most cases Firebase it is automatically initialized the first time its services are accessed, but for explicit control it is recommended to add initialization in the class Application.

Create a class that inherits from android.app.Applicationand override the method onCreate():

class MyApplication : Application() {

override fun onCreate() {

super.onCreate()

// Firebase Initialization

FirebaseApp.initializeApp(this)

}

}

Don't forget to register this class in AndroidManifest.xml:

<application

android:name=".MyApplication"

...>

</application>

To check functionality Firebase you can send a test event to Analytics. Add the following code to the activity:

Firebase.analytics.logEvent("test_event", null)

To see the event in Firebase Console, follow these steps:

  1. Run the application on the device or emulator.
  2. Open Firebase Console โ†’ select your project โ†’ go to section "Analytics" โ†’ "Events".
  3. Wait 24 hours (data is not updated instantly) or use "DebugView" for debugging.
โš ๏ธ Attention: If you are testing on an emulator, make sure it has access to the Internet. To do this, in the emulator settings (... โ†’ Settings), enable the option "Use detected proxy settings" or configure the proxy manually.
๐Ÿ’ก

To speed up Analytics debugging, use the command adb shell setprop debug.firebase.analytics.app com.example.myapp, where com.example.myapp is your applicationId. This will enable debug mode.

5. Setting up Firebase Authentication

Firebase Authentication allows you to add user registration and authorization to the application via email/password, Google, Facebook, phone and other providers. To begin, enable the authentication method in Firebase Console:

  1. Go to the section "Authentication" โ†’ "Sign-in method".
  2. Click "Add new provider" and select the one you need (for example, Email/Password).
  3. Turn on the switch and save the settings.

Now add the code to register a new user. For example, for authentication by email/password:

Firebase.auth.createUserWithEmailAndPassword("user@example.com", "password123")

.addOnCompleteListener { task ->

if (task.isSuccessful) {

// User is registered

val user = Firebase.auth.currentUser

} else {

// Error registration

Log.w("Auth", "Registration failed", task.exception)

}

}

To log in for an existing user, use:

Firebase.auth.signInWithEmailAndPassword("user@example.com", "password123")

.addOnCompleteListener { task ->

if (task.isSuccessful) {

// User logged in

val user = Firebase.auth.currentUser

} else {

// Login error

Log.w("Auth", "Sign-in failed", task.exception)

}

}

  • ๐Ÿ”’ For security, configure access rules in Firebase Console (section "Authentication" โ†’ "Templates").
  • ๐Ÿ“ง Use email verification (user.isEmailVerified) to confirm user addresses.
  • ๐Ÿ”„ Implement password recovery via Firebase.auth.sendPasswordResetEmail(email).
โš ๏ธ Attention: If you use Google Sign-In, do not forget to add SHA-1 the release key to the project settings Firebase. Otherwise, authorization via Google will not work in the release version of the application.
What to do if the user does not receive a confirmation email?

Check the "Spam" folder in your email mailbox.|Make sure that the "Email/Password" authentication method is enabled in the Firebase Console.|Configure the email template in the Firebase Console (section "Authentication" โ†’ "Templates").|Check that your email domain is not blocked (for example, some corporate domains block emails from Firebase).

6. Working with Firebase Realtime Database

Firebase Realtime Database is a cloud database that synchronizes data between clients in real time. To start using it, first set up access rules in Firebase Console:

  1. Go to the section "Realtime Database".
  2. Click "Get started" and select mode "Test mode" (for development) or "Blocked mode" (for production).
  3. Configure security rules (example for test mode):
    {
    

    "rules": {

    ".read": true,

    ".write": true

    }

    }

To write data to the database, use the following code:

val database = Firebase.database

val myRef = database.getReference("message")

myRef.setValue("Hello, Firebase!")

.addOnSuccessListener {

Log.d("Database", "Data saved successfully")

}

.addOnFailureListener { error ->

Log.w("Database", "Error saving data", error)

}

To read the data and monitor its changes in real time, add a listener:

val postListener = object : ValueEventListener {

override fun onDataChange(snapshot: DataSnapshot) {

val value = snapshot.getValue(String::class.java)

Log.d("Database", "Value is: $value")

}

override fun onCancelled(error: DatabaseError) {

Log.w("Database", "Failed to read value", error.toException())

}

}

myRef.addValueEventListener(postListener)

  • ๐Ÿ“Š For structured data, use objects instead of primitive types (for example, data class User(val name: String, val age: Int)).
  • ๐Ÿ”„ Disable listeners when they are no longer needed (for example, in onDestroy() activities) to avoid memory leaks.
  • ๐Ÿ“ˆ For complex queries, use orderByChild(), equalTo() and other filtering methods.
Method Description Example
setValue() Writes data to the specified link (replaces existing ones) ref.setValue("New data")
updateChildren() Updates only the specified fields without affecting the others ref.updateChildren(mapOf("field1" to "value1"))
addValueEventListener() Listens to changes in data (including the initial state) ref.addValueEventListener(listener)
addChildEventListener() Listens to changes in child elements ref.addChildEventListener(listener)
โš ๏ธ Attention: In test mode, access rules for the Realtime Database allow reading and writing for all users. Before releasing your application, be sure to set up security rules, otherwise your database will become vulnerable to attacks.
๐Ÿ’ก

To optimize your work with Realtime Database, use indexes. Add the ".indexOn": ["field1", "field2"] rule to the JSON database configuration if you frequently query these fields.

7. Debugging and solving common errors

When integrating Firebase developers often encounter errors that are difficult to diagnose. Let's look at the most common problems and ways to solve them:

  • ๐Ÿšซ Error: "Could not find com.google.firebase:firebase-core"
    Cause: Outdated version Firebase BoM or library conflict.
    Solution: Update the version BoM in build.gradle or remove the explicit instruction firebase-core (it turns on automatically).
  • ๐Ÿ”ฅ Error: "Default FirebaseApp is not initialized"
    Reason: The file google-services.json is missing or incorrectly placed.
    Solution: Check that the file is in the folder appand rebuild the project.
  • ๐Ÿ”’ Authentication error: "The email address is badly formatted"
    Cause: Incorrect email format or empty field.
    Solution: Check the entered data using a regular expression:
    val emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+"
  • ๐Ÿ“ก Realtime Database is not updated in real time
    Cause: There is no Internet connection or the security rules are incorrectly configured.
    Solution: Check your network connection and access rights in Firebase Console.

For detailed debugging, use Firebase Local Emulator Suite. This tool allows you to test Firebaseservices locally, without connecting to a real database. To set it up:

  1. Install emulators via Android Studio (Tools โ†’ Firebase โ†’ Emulators).
  2. Add initialization of emulators to the code:
    Firebase.database.useEmulator("10.0.2.2", 9000)
    

    Firebase.auth.useEmulator("10.0.2.2", 9099)

  3. Run emulators via terminal:
    firebase emulators:start

If the problem is not solved, study the logs in Logcat (filter by tag "Firebase"). They often contain detailed error messages that are not displayed in the user interface.

8. Optimization and best practices

Correct integration Firebase is not only performance, but also optimization of performance, security and cost. Follow these recommendations:

  • ๐Ÿ›ก๏ธ Security:
    • Configure access rules in Realtime Database i Storage so that users have access only to their data.
    • Use Firebase App Check to protect against bots and illegitimate requests.
    • Enable two-factor authentication for the account Googleassociated with Firebase.
  • โšก Performance:
    • Limit the number of listeners Realtime Database. For example, instead of listening to the entire database, subscribe only to the nodes you need.
    • Use .indexOn to speed up queries.
    • Cache data locally with FirebaseDatabase.getInstance().setPersistenceEnabled(true).
  • ๐Ÿ’ฐ Cost:
    • Monitor resource usage in Firebase Console (section "Usage and billing").
    • Set up alerts when limits are exceeded (for example, the number of reads from the database).
    • Use Firebase Spark Plan (free plan) for development and testing.

For large projects, consider the ability to divide Firebaseservices into several projects. For example:

  • One project for Authentication and Analytics.
  • A separate project for Realtime Database and Storage.

This will simplify management access rights and monitoring of expenses.

It is also useful to automate deployment using Firebase CLI. For example, to deploy security rules Realtime Database use the command:

firebase deploy --only database
โš ๏ธ Attention: Details of tariff plans and limits Firebase may change. Before switching to a paid plan, check the current conditions in Firebase Console or the official documentation.
๐Ÿ’ก

To speed up development, use Firebase Extensions For example, the "Trigger Email" extension allows you to automatically send an email when data changes in Realtime. Database.

FAQ: Frequently asked questions

Can I use Firebase without the Internet?

Firebase Realtime Database and Cloud Firestore support offline mode Data is cached locally and synchronized when a connection is available. To enable this feature, add. line:

FirebaseDatabase.getInstance().setPersistenceEnabled(true)

For Cloud Firestore offline mode is enabled by default.

How to transfer a Firebase project to another Google account?

Transferring a project between accounts is not possible directly. Instead:

  1. Create a new project in Firebase Console under the desired account.
  2. Export data from the old project (for example, via Realtime Database REST API).
  3. Import the data into the new project.
  4. Update the configuration file google-services.json in the application.

For Authentication user transfer is possible via Firebase CLI using the command firebase auth:export.

Why does Firebase Analytics not show data?

Reasons may be as follows:

  • Data is updated with a delay of up to 24 hours.
  • In Firebase Console not enabled Google Analytics (check the project settings).
  • There is no Internet on the device or traffic is blocked (for example, through VPN or a firewall).
  • The initialization method is not called Analytics (check that FirebaseApp.initializeApp() is completed).

For debugging, use "DebugView" in Firebase Console.

How to reduce the size of an APK when using Firebase?

Firebaselibraries can significantly increase the size APKTo optimize it:

  • Use ProGuard or R8 to remove unused code. Add to proguard-rules.pro:
    -keep class com.google.firebase.** { *; }
  • Connect only necessary modules Firebase (for example, if you do not use Analyticsadd firebase-analytics).
  • Use Android App Bundle instead of APK for dynamic delivery of functions.

Also check for duplicate libraries (for example, if you included play-services-auth separately, but it is already included in Firebase BoM).

Is it possible to use Firebase in an application without Google Play Services?

Yes, Firebase works on devices without Google Play Services (for example, on Huawei or custom firmware). To do this:

  1. Use Firebase without Google Play Services (connect libraries with the suffix -no-gms).
  2. Set up manual initialization Firebase via FirebaseOptions.

However, some functions (for example FCM) may be limited.