DEV Community

Cover image for Automating Firebase App Distribution for Android and iOS
Amit Kumar
Amit Kumar

Posted on

Automating Firebase App Distribution for Android and iOS

In this blog, we’ll walk through automating the process of distributing Android and iOS builds using Firebase App Distribution. This process ensures a seamless workflow for testing by leveraging Firebase CLI and a custom script that handles Android APK and iOS IPA distributions with ease.

Folder Setup

First, let's create the required folder structure in your project to manage Firebase App Distribution efficiently.

  1. Navigate to your project's root directory.
  2. Create a folder named distribution inside config/scripts/.
mkdir -p config/scripts/distribution

Enter fullscreen mode Exit fullscreen mode
  1. Inside the distribution folder, create two files:
  • firebase-distribution.sh: This will be the shell script that automates the distribution.
  • release_notes_file.txt: This file will store your release notes for each version.
touch config/scripts/distribution/firebase-distribution.sh
touch config/scripts/distribution/release_notes_file.txt

Enter fullscreen mode Exit fullscreen mode

Folder structure after creation:


Firebase Distribution Script

Next, we’ll create a custom shell script that automates the distribution process. Open firebase-distribution.sh and add the following content:

#Set App Distribution Properties
##############################################
# App name on ipa file (FILE_NAME.ipa)
FILE_NAME="ipaFileName"

# Firebase App IDs
FIREBASE_APP_ID_ANDROID="1:46:android:36f84"
FIREBASE_APP_ID_IOS="1:46:ios:36f84"

# Distribution Group Ids
INTERNAL_GROUP_APP_ID="appIdOfDistributionGroup"
DEVELOPERS_GROUP_APP_ID="appIdOfDistributionGroup"

##############################################

# Firebase CLI path
FIREBASE_CLI_PATH="firebase"

# APK and IPA paths
APK_PATH="android/app/build/outputs/apk/release/app-release.apk"
IPA_PATH="src/config/scripts/distribution/release/$FILE_NAME.ipa"

# Tester group and release notes paths
TESTERS_FILE_PATH=$DEVELOPERS_GROUP_APP_ID
RELEASE_NOTES_FILE_PATH="src/config/scripts/distribution/release_notes_file.txt"

# Platform selection options
options=("Android🤖" "iOS🍎")
selected_platform=""

echo "\n\n"
echo "📲 Please select Platform:"
REPLY=1  # Set default option to Android
select choice in "${options[@]}"; do
    case $choice in
        "Android🤖")
          echo "Android selected ✅"
            selected_platform="Android"
            ;;
        "iOS🍎")
          echo "iOS selected ✅"
            selected_platform="iOS"
            ;;
        *)
            echo "Invalid option. Please try again."
            ;;
    esac
    if [ -n "$selected_platform" ]; then
        break
    fi
done

# Setting parameters based on the platform
if [ "$selected_platform" = "Android" ]; then
    FILE_PATH="$APK_PATH"
    APP_ID="$FIREBASE_APP_ID_ANDROID"
else
    FILE_PATH="$IPA_PATH"
    APP_ID="$FIREBASE_APP_ID_IOS"
fi

# Distribution group selection
share_groups_options=("Internal Testing" "Developers")
echo "\n\n"
echo "🧑 Please select Distribution Group:"
REPLY=1  # Set default option to Internal Testing
select choice in "${share_groups_options[@]}"; do
    case $choice in
        "Internal Testing")
            echo "Internal Testing group selected ✅"
            TESTERS_FILE_PATH=$INTERNAL_GROUP_APP_ID
            ;;
        "Developers")
          echo "Developers group selected ✅"
            TESTERS_FILE_PATH=$DEVELOPERS_GROUP_APP_ID
            ;;
        *)
            echo "Invalid option. Please try again."
            ;;
    esac
    if [ -n "$TESTERS_FILE_PATH" ]; then
        break
    fi
done

# Check if Firebase CLI is installed
if [ ! "$FIREBASE_CLI_PATH" ]; then
  echo "Firebase CLI is not installed. Please install it."
  exit 1
fi

# Validate file paths and release notes
if [ ! -f "$FILE_PATH" ]; then
  echo "File does not exist at the provided path."
  exit 1
fi
if [ ! -f "$RELEASE_NOTES_FILE_PATH" ]; then
  echo "Release notes file not found."
  exit 1
fi

RELEASE_NOTES=$(cat "$RELEASE_NOTES_FILE_PATH")

# Display selected options
echo "\n---------------------------------------------\n"
echo "📱 Platform: $selected_platform\n"
echo "📦 Distribution group: $TESTERS_FILE_PATH\n"
echo "📝 Release Notes: $RELEASE_NOTES"
echo "\n---------------------------------------------\n"
echo "Press Enter to continue...↩️"
read

# Distribute using Firebase CLI
"$FIREBASE_CLI_PATH" appdistribution:distribute "$FILE_PATH" \
  --app "$APP_ID" \
  --release-notes "$RELEASE_NOTES" \
  --groups "$TESTERS_FILE_PATH"

Enter fullscreen mode Exit fullscreen mode

Key Details:

  • **Firebase App IDs:** Get your Firebase App IDs from the Firebase console. Navigate to your app’s settings, and you’ll find the App ID under the "Your apps" section.
  • **Distribution Group IDs:** To find or create tester groups, navigate to the App Distribution section of Firebase, click on "Testers & Groups," and note the group ID next to the group name.

Screenshot for group ID reference:


Firebase CLI Installation

You need the Firebase CLI to automate the upload process. Follow these steps to install and configure it:

  1. Install Firebase CLI globally:
npm install -g firebase-tools

Enter fullscreen mode Exit fullscreen mode
  1. Log in to Firebase via CLI:
firebase login

Enter fullscreen mode Exit fullscreen mode

Distributing the Build

Once the script is ready and Firebase CLI is configured, follow these steps:

1. Create Android/iOS Release Build:

  • Generate your APK or IPA file.

  • Create IOS build and put ipa file in "src/config/scripts/distribution/release" folder

3. Update Release Notes:

  • Add your release notes in release_notes_file.txt.

Run the Script:

  • Run the custom script using Yarn or npm:
yarn share

Enter fullscreen mode Exit fullscreen mode

4. Platform and Group Selection:

  • Follow the prompts to select the platform (Android or iOS) and the distribution group (Internal or Developers).

5. Confirmation:

  • Press Enter to confirm and the build will be uploaded to Firebase App Distribution!

Handling Upload Errors

If you encounter issues during the upload process (e.g., Firebase CLI not installed correctly), ensure the following:

  1. Reinstall Firebase CLI:
npm install -g firebase-tools

Enter fullscreen mode Exit fullscreen mode
  1. Log in again:
firebase login

Enter fullscreen mode Exit fullscreen mode

With this setup, you’ve automated the tedious process of distributing Android and iOS builds, streamlining the testing workflow for your team. This script not only saves time but also reduces human error, ensuring that the latest version of your app is always available for testers. Happy coding! 🎉

Top comments (0)