AjapaReporter

Home life · Updated

How to Implement Firebase in Your App

Time it takes30 min
Steps6in the list below
LevelMediumsome care needed
Official sourceFirebase Documentationcheck it for changes

Quick answer Start by creating a Firebase project in the Firebase console, then add your app's platform (Android, iOS, or web) and follow the setup steps to install the SDK and initialize Firebase in your code.

Create Your Firebase Project

Go to the Firebase console and sign in with your Google account. Click Add project, enter a project name, and choose whether to enable Google Analytics (you can skip it for now). After the project is created, you’ll land on the project overview page. This is the control center for all Firebase services you’ll use.

If you’re building both a mobile app and a web app, you can add multiple platforms to the same Firebase project. Each platform gets its own configuration object, but they all share the same backend data and authentication users.

Add Your App to the Project

From the project overview, click the platform icon that matches your app: Android (the green robot), iOS (the Apple logo), or Web (the </> symbol). Each platform has slightly different steps:

  • Android: Enter your app’s package name (like com.example.myapp). Download the generated google-services.json file and place it in your app’s app/ folder. Then add the Google Services plugin to your Gradle files.
  • iOS: Enter your app’s bundle ID (like com.example.myapp). Download the GoogleService-Info.plist file and add it to your Xcode project. Then add the Firebase SDK via CocoaPods or Swift Package Manager.
  • Web: Enter a nickname for your app (like “My Web App”). The console shows a configuration object with your API key, auth domain, project ID, and other keys. Copy this snippet—you’ll paste it into your code.

After registering the app, you’ll see a configuration snippet. For web, it looks like this:

const firebaseConfig = {
  apiKey: "your-api-key",
  authDomain: "your-project.firebaseapp.com",
  projectId: "your-project-id",
  storageBucket: "your-project.appspot.com",
  messagingSenderId: "1234567890",
  appId: "1:1234567890:web:abc123"
};

For Android and iOS, the config files contain the same information, but you don’t need to copy it manually—the SDK reads it from the file.

Install the Firebase SDK

Each platform has its own installation method. The steps below assume you have a basic project set up already.

Android (Gradle)

Add the Google Services plugin to your project-level build.gradle file:

plugins {
    id 'com.google.gms.google-services' version '4.4.2' apply false
}

Then in your app-level build.gradle, apply the plugin and add the Firebase dependencies you need (for example, Firebase Authentication, Firestore, or Realtime Database):

apply plugin: 'com.google.gms.google-services'

dependencies {
    implementation platform('com.google.firebase:firebase-bom:33.5.1')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-firestore'
}

Sync your project and you’re ready to code.

iOS (CocoaPods)

Create a Podfile in your project folder if you don’t have one, and add the Firebase pods you need:

platform :ios, '13.0'

target 'YourAppName' do
  use_frameworks!
  pod 'FirebaseAuth'
  pod 'FirebaseFirestore'
end

Run pod install in the terminal. Open the newly created .xcworkspace file (not the .xcodeproj) from now on.

Web (npm)

In your project folder, run:

npm install firebase

Then import Firebase in your JavaScript file:

import { initializeApp } from "firebase/app";

const app = initializeApp(firebaseConfig);

You can also use Firebase from a CDN if you’re not using a bundler, but npm is the standard for most modern web projects.

Initialize Firebase in Your Code

Now that the SDK is installed, you need to initialize Firebase before you can use any service. This is a one-time setup that connects your app to your Firebase project.

Android (Kotlin/Java)

In your main Activity or Application class, add:

// Kotlin
FirebaseApp.initializeApp(this)

That’s it—the SDK reads google-services.json automatically.

iOS (Swift)

In your AppDelegate, inside didFinishLaunchingWithOptions, add:

import Firebase

FirebaseApp.configure()

The SDK picks up GoogleService-Info.plist automatically.

Web (JavaScript)

After importing initializeApp, call it with your config object:

const app = initializeApp(firebaseConfig);

Now app is your Firebase app instance. You can use it to get services like Auth or Firestore:

import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";

const auth = getAuth(app);
const db = getFirestore(app);

Use a Firebase Service

Firebase offers many services: Authentication, Firestore (a NoSQL database), Realtime Database, Storage, Cloud Functions, and more. To see that your setup works, try a simple operation with one service.

For example, with Firestore on the web, add a test document:

import { doc, setDoc } from "firebase/firestore";

await setDoc(doc(db, "users", "test"), {
  name: "Test User",
  email: "test@example.com"
});

Then check the Firestore database in the Firebase console (under Build > Firestore Database) to see if the document appears. If it does, your integration is working.

For Authentication, you can enable a sign-in method (like Email/Password) in the console, then use the SDK to create a user:

import { createUserWithEmailAndPassword } from "firebase/auth";

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

You’ll see the new user appear in the Authentication section of the console.

Verify It Works

After implementing a service, check three things:

  1. No console errors: Open your browser’s developer console (or Android Logcat / Xcode console) and look for red errors or warnings about Firebase.
  2. Data appears in the console: For databases, add a test record and refresh the Firebase console to see it. For authentication, sign up a test user and check the Users tab.
  3. Network requests succeed: In the browser’s Network tab, you should see requests to firestore.googleapis.com or identitytoolkit.googleapis.com with a 200 status.

If you see an error like “Firebase: Error (auth/invalid-api-key)”, it means your configuration is wrong—double-check that you copied the correct config object or that your google-services.json file matches the package name.

Common Setup Failure: Wrong Package Name

The most common failure when setting up Firebase on Android or iOS is a mismatch between the package/bundle ID you registered in the console and the one in your actual app. For Android, check your app/build.gradle file’s applicationId—it must exactly match the package name you entered in the Firebase console. For iOS, check your Xcode project’s Bundle Identifier under the General tab. If they don’t match, the SDK will throw an error like “Default FirebaseApp is not initialized” or “GoogleService-Info.plist cannot be found”.

Fix: Update the application ID or bundle identifier in your project to match the one you registered, or re-register the app in the console with the correct ID. Then download the config file again and replace the old one.

Frequently Asked Questions

Do I need a billing plan to use Firebase?

No. Firebase has a free tier (the Spark plan) that includes generous quotas for most services, like 50,000 reads and 20,000 writes per day in Firestore, and 10 GB of storage. You can start with the free plan and upgrade later if you need more.

Can I use Firebase with a backend I already have?

Yes. Firebase can complement an existing backend. For example, you can use Firebase Authentication for user sign-in and keep your own server for business logic. Firebase also offers client SDKs that work alongside your existing API.

How do I add Firebase to an existing app?

Adding Firebase to an existing app is the same as starting fresh—you create a Firebase project, add your app’s platform, install the SDK, and initialize. The only difference is you might need to be careful about your existing build configuration (like Gradle or Podfile) to avoid conflicts.

Sources: Firebase Documentation. Menus and buttons can differ slightly by version. Spotted something out of date? Tell us.