Skip to content

Firebase Project Setup

Sk Niyaj Ali edited this page Dec 25, 2024 · 2 revisions

Table of Contents

  1. Creating a Firebase Project
  2. Registering an Android App
  3. Registering an iOS App
  4. GitHub Actions CI/CD Setup

Creating a Firebase Project

Prerequisites

Steps to Create a Project

  1. Access Firebase Console

  2. Create New Project

    • Click "Create Project" or "Add Project"
    • Enter a project name (this will be visible to your team)
    • Choose whether to enable Google Analytics (recommended)
    • Accept the Firebase terms of service
    • Click "Create Project"
  3. Configure Project Settings

    • Once created, you'll be taken to the project dashboard
    • Click the gear icon next to "Project Overview" to access project settings
    • Note your Project ID as you'll need it later

Registering an Android App

Prerequisites

  • Android Studio installed
  • Your app's package name
  • A development machine running Linux, macOS, or Windows

Steps to Register Android App

  1. Add Android App to Firebase

    • In Firebase Console, click the Android icon (</>) on the project overview page
    • Enter your Android app's package name (e.g., com.company.appname)
    • Enter app nickname (optional)
    • Enter SHA-1 signing certificate (optional, but recommended for features like Google Sign-In)
    • Click "Register App"
  2. Download Configuration File

    • Download the google-services.json file
    • Move the file into your Android app module's root directory
    • Usually located at /app/google-services.json

Registering an iOS App

Prerequisites

  • Xcode installed
  • Apple Developer account
  • Your app's Bundle ID
  • CocoaPods installed (if using)

Steps to Register iOS App

  1. Add iOS App to Firebase

    • In Firebase Console, click the iOS icon (</>) on the project overview page
    • Enter your iOS bundle ID (e.g., com.company.appname)
    • Enter app nickname (optional)
    • Enter App Store ID (optional)
    • Click "Register App"
  2. Download Configuration File

    • Download the GoogleService-Info.plist file
    • Add the file to your Xcode project
    • Make sure to add it to all appropriate targets
    • Select "Copy items if needed" when adding

GitHub Actions CI/CD Setup

Encoding google-services.json for GitHub Secrets

1. Convert google-services.json to Base64

On macOS/Linux:

base64 -i app/google-services.json

On Windows (PowerShell):

[Convert]::ToBase64String([System.IO.File]::ReadAllBytes("app/google-services.json"))

Or Use Web to encode or decode files here

2. Store in GitHub Secrets

  • Go to your GitHub repository
  • Navigate to Settings > Secrets and variables > Actions
  • Click "New repository secret"
  • Name: GOOGLE_SERVICES_JSON
  • Value: Paste the entire Base64 encoded string
  • Click "Add secret"

3. Use in GitHub Actions Workflow

Create or modify your workflow file (e.g., .github/workflows/android-build.yml):

name: Android CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v3
    
    - name: Set up JDK
      uses: actions/setup-java@v3
      with:
        java-version: '17'
        distribution: 'temurin'
        
    - name: Decode google-services.json
      env:
        GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
      run: |
        echo $GOOGLE_SERVICES_JSON | base64 -d > app/google-services.json
        
    - name: Grant execute permission for gradlew
      run: chmod +x gradlew
      
    - name: Build with Gradle
      run: ./gradlew build