Backend & Infrastructure
Firebase Setup Guide: Add Firebase to Android and Web
Firebase connects your app to Google's backend services — authentication, databases, storage, and more. This guide walks through creating a Firebase project and integrating it into an Android or web application from scratch.
Step 1: Create a Firebase Project
- 1Go to console.firebase.google.com and sign in with your Google account.
- 2Click Add project, enter a project name, and optionally enable Google Analytics.
- 3Wait for project creation to complete, then click Continue.
Step 2: Register Your App
From the Project Overview page, click the platform icon to register your app:
Android
- Click the Android icon
- Enter your app's package name (e.g.
com.example.myapp) - Optionally add a nickname and SHA-1 fingerprint
- Download
google-services.json - Place it in your
app/directory
Web
- Click the web icon
</> - Enter an app nickname
- Optionally set up Firebase Hosting
- Copy the Firebase config object shown
Step 3: Add Firebase SDK
Android (Gradle)
// Project-level build.gradle (or settings.gradle with plugins block)
plugins {
id("com.google.gms.google-services") version "4.4.0" apply false
}
// App-level build.gradle
plugins {
id("com.google.gms.google-services")
}
dependencies {
// Firebase BoM — manages version compatibility
implementation(platform("com.google.firebase:firebase-bom:33.1.0"))
implementation("com.google.firebase:firebase-analytics")
// Add other Firebase products as needed:
// implementation("com.google.firebase:firebase-auth")
// implementation("com.google.firebase:firebase-firestore")
}Web (npm)
npm install firebase
// src/firebase.js
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_PROJECT.firebaseapp.com",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_PROJECT.appspot.com",
messagingSenderId: "YOUR_SENDER_ID",
appId: "YOUR_APP_ID"
};
const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);Step 4: Verify the Setup
Run your app. If Firebase is configured correctly, you should see your app appear in the Firebase Console under the project overview within a few minutes of the first launch.
Common setup errors
- Wrong
google-services.jsonlocation — must be inapp/ - Package name mismatch between the JSON and your app's
applicationId - Missing Google Services plugin in
build.gradle - Stale config file — re-download from Firebase Console after adding services
Next Steps
- Enable Authentication in the Firebase Console and add sign-in providers
- Set up Firestore or Realtime Database and write Security Rules
- Configure Cloud Storage for file uploads
- Add Firebase App Check to prevent unauthorized API access
Related Resources
Z
Written by Zhisan
Independent Developer · Last updated June 2026