How do you integrate Firebase in an Android/iOS app?

Integrating Firebase in an Android/iOS App

Firebase provides various services like Authentication, Firestore, FCM, and more. Below is a step-by-step guide to integrating Firebase into an Android and iOS app.


Android Integration :

1. Create a Firebase Project
  1. Go to Firebase Console.
  2. Click "Add project", enter a name, and set up Google Analytics if needed.
  3. Click "Create project".

2. Add Firebase to Your Android App
  1. In Firebase Console, click "Add App" → Android.
  2. Enter your app’s package name (e.g., com.example.myapp).
  3. Download the google-services.json file and place it inside:
    app/src/main/
    
  4. Add Firebase SDK dependencies:
    • Open build.gradle (Project level):
      dependencies {
          classpath 'com.google.gms:google-services:4.3.10' // Ensure latest version
      }
      
    • Open build.gradle (Module level - app):
      plugins {
          id 'com.google.gms.google-services' // Add this at the bottom
      }
      
      dependencies {
          implementation platform('com.google.firebase:firebase-bom:32.0.0')
          implementation 'com.google.firebase:firebase-analytics'
      }
      
  5. Sync Gradle and rebuild the project.

3. Initialize Firebase in Your Android App
  • In your MainActivity.kt (Kotlin):
    import com.google.firebase.analytics.FirebaseAnalytics
    import com.google.firebase.analytics.ktx.analytics
    import com.google.firebase.ktx.Firebase
    
    class MainActivity : AppCompatActivity() {
        private lateinit var firebaseAnalytics: FirebaseAnalytics
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
    
            // Initialize Firebase Analytics
            firebaseAnalytics = Firebase.analytics
        }
    }
    


iOS Integration :
1. Create a Firebase Project

(Same steps as Android)


2. Add Firebase to Your iOS App
  1. In Firebase Console, click "Add App" → iOS.
  2. Enter your app’s Bundle ID (e.g., com.example.myiosapp).
  3. Download the GoogleService-Info.plist file.
  4. Drag the GoogleService-Info.plist into the Xcode Runner directory.

3. Install Firebase SDK
  • Open Terminal and navigate to your project folder:
    cd ios
    pod init
    
  • Open the Podfile and add:
    platform :ios, '10.0'
    use_frameworks!
    pod 'Firebase/Core'
    
  • Install dependencies:
    pod install
    
  • Open the .xcworkspace file in Xcode.

4. Initialize Firebase in iOS
  • Open AppDelegate.swift and modify:
    import UIKit
    import Firebase
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
    
        func application(_ application: UIApplication,
            didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            FirebaseApp.configure()
            return true
        }
    }
    


Testing Firebase Integration
  • For Android:
    adb logcat -s Firebase
    
  • For iOS:
    Xcode → Run App → Debug Console
    


Common Firebase Services to Integrate Next

* Firebase Authentication – User login/sign-up
* Cloud Firestore – Real-time database
* Firebase Cloud Messaging (FCM) – Push notifications
* Firebase Remote Config – Dynamic app updates