Skip to content

Instantly share code, notes, and snippets.

@AmrSaleh
Created December 3, 2019 12:46
Show Gist options
  • Save AmrSaleh/0ebe40c1704a12548d73dde6e0461eb1 to your computer and use it in GitHub Desktop.
Save AmrSaleh/0ebe40c1704a12548d73dde6e0461eb1 to your computer and use it in GitHub Desktop.
Explained steps to migrate your Android/IOS Project to use Firebase Analytics and App distribution instead of Fabric Crashlytics and Beta distribution.

Fabric to Firebase

FabricFirebase

As we all know that Fabric is being migrated to Firebase and all Fabric features (Crashlytics, Beta, etc.) will have their equivalents in Firebase (Analytics, Distribution, etc.)

As a result we will need to migrate our current Fabric projects to Firebase in order to keep our analytic data and continue using other features like Beta distribution.

In this article I will try to simplify all the steps needed to migrate you project to Firebase, keep your analytics and configure automated releases using Fastlane and CircleCI.

Migration steps from Fabric to Firebase.

Prerequisites

  • Make sure you have access to Fabric project.
  • If you have already a Firebase project for notifications for example make sure to have access to it. Otherwise, we will create a new Firebase project later.

Migrating Fabric analytics to the Firebase project (Linking Fabric and Firebase projects)

A very important step in migrating to Firebase is actually keeping all your analytic data gathered in the Fabric project. In this step we will make sure to connect both our old Fabric project and our new Firebase project to insure all our analytic data is safe and migrated.

  1. Open your Fabric project dashboard and you should see "NOT MIGRATED" sign right under the project name. You can start the migration by clicking the "Firebase Migration" button right under the sign.

Screen Shot 2019-11-27 at 2 14 49 PM

  1. You will be redirected to another page with some useful info. Scroll down and click the "Sign in with google" then choose the google account that has access to the Firebase project or the one you will use to create the new project.

Screen Shot 2019-11-27 at 2 16 47 PM

Screen Shot 2019-11-27 at 2 17 03 PM

  1. You will arrive at a 2-steps for migration page. The first step is to "Migrate apps" and the second one is to "Invite team" which we will talk about later. Now, click "Migrate apps".

Screen Shot 2019-11-27 at 2 12 43 PM

  1. Now you should see all your existing Fabric projects on the left and your Firebase projetcs (if any) on the right. Screen Shot 2019-11-27 at 2 20 18 PM
If you find an already matching Firebase project
  1. Simply drag the project from the left hand side to the right into the matching project.

  2. Review the pending links section then click next.

  3. Click "Migrate apps" Screen Shot 2019-11-27 at 2 21 37 PM

  4. Watch the nice animated rocket move from Fabric planet to Firebase planet that resembles all you data being copied over to Firebase. Afterwards, you get the "App migrated successfully page." Screen Shot 2019-11-27 at 2 22 23 PM

  5. You can view the firebase page at this point or click "Done" and you will be redirected back to the 2-steps migration page and are ready for the next step "Inviting team".

If you don't have a matching Firebase project and will create a new one.
  1. Simply drag the project you want to migrate into the "Create a new Firebase project" area.

Screen Shot 2019-11-27 at 2 33 48 PM

  1. A window will open and guide you through the steps of creating a new Firebase project. After following the creation steps you will be ready for the "Invite team" step.

Screen Shot 2019-11-27 at 2 33 18 PM

Inviting your team members to the Firebase project

You can do this in two different ways

You are at the 2-step migration page
  • You can click "Invite teammates for me button" and review a list of team members who already have access to the Fabric project and the wizard will invite them for your Firebase project. Screen Shot 2019-11-27 at 2 46 54 PM

  • You can also click "Invite teammates manually" and you will be redirected to Firebase users & permissions and then you can add their emails manually.

You Can also visit your Firebase project and add them manually
  • Click the cog icon next to your project name and select "users and permissions" and from there you can add members manually. Screen Shot 2019-11-27 at 2 51 08 PM Screen Shot 2019-11-27 at 2 45 20 PM

Setting up Firebase App Distribution (Fabric Beta equivalent)

A very important feature that Fabric provided was called "Beta" which allowed us to publish builds to our testers with ease and even automate the builds. An equivalent feature to that that Firebase provides is called "App Distribution". In this section we will go through the steps required to set this up.

  1. Go to the Firebase project and click the "App Distribution" tab and click the "Get started" button. This is actually a very important step and is required even if you plan only distribute using automated continuous integration tools.

Screen Shot 2019-11-27 at 2 53 59 PM

  1. Now you will be able to upload an APK to be distributed and select the testers to distribute to.

Screen Shot 2019-12-02 at 1 31 01 PM

  1. We need to focus here on setting up testers and groups by going to the "Testers and Groups" tab and add a group with all the testers you would like to automatically publish to when we set up Fastlane.

Screen Shot 2019-11-27 at 2 58 12 PM

Configuring Fastlane for continuous integration.

Now we need to set up our Fastlane file in order to automate the distribution. I am assuming you already have Fastlane setup and will ony focus on the Fastfile configurations to distribute on Firbase. otherwise please refer to the Fastlane guides to set it up.

Firebase provides a very good official guide on setting this up but we will only focus on some few hints and give fastfile samples.

  1. Install or update to the latest version of the Firebase CLI using this command in the console:
curl -sL firebase.tools | bash

If this command doesn't work for you refer to the Firebase ClI page for other options.

  1. We want to use firebase with CI so we need to get the FIREBASE_TOKEN. To do that we will start the signin process by running the following command:
firebase login:ci

Visit the URL provided, then sign in using a Google account. Print a new refresh token. The current CLI session will not be affected.

  1. Store the output token in a secure but accessible way in your system. We will need to plug that into our CI later on so keep this token for now.

  2. Add App Distribution to your fastlane configuration by running the following command from the root of your Android project:

fastlane add_plugin firebase_app_distribution

If the command prompts you with an option, select Option 3: RubyGems.org

  1. In a lane in your ./fastlane/Fastfile, add a firebase_app_distribution block. You can find complete description of each parameter on the Firebase distribution guidlines page. However, we will suffice by showing you an example with most important attributes right now.
platform :android do
      desc "My awesome app"
      lane :distribute do
          build_android_app(...) # build_android_app is a built-in fastlane action.

          firebase_app_distribution(
              app: "1:123456789:android:abcd1234", # Your app id found on Project settings page on Firebase
              groups:"mcd_internal", # A group identifier for the testers group we defined on the Firebse testers page
              release_notes_file: "release_notes.txt" # Path to the file containing the release notes
              #testers: "tester1@company.com, tester2@company.com", # Emails for testers (I prefer using groups instead)
              #release_notes: "Lots of amazing new features to test out!", # You can write release notes directly here (I prefer using the file option instead)
              #firebase_cli_path: "/absolute/path/to/firebase/cli/binary", # If you know what you are doing and installed the Firebase CLI in a path different than the default one specify it here otherwise remove this property
              #firebase_cli_token: "refresh token for CLI" # A refresh token that's printed when you authenticate your CI environment with the Firebase CLI (you don't need this if you are planning on adding the token as an environment variable)
          )

      end
  end
  1. At this point your Fastlane configuration should be done. And you can run the lane locally by running the lane in .
fastlane <lane>

Configuring CircleCI

A very important step in automating our releases is selecting a continuous integration provider and setting it up. In our case we already have our circleci installed and configured. We will only focus on the changes we need to make in order to distribute with firebase.

  1. Remember the FIREBASE_TOKEN we got by loging in to Firebase CLI. We need to add that to the environment variables of circle. We need to use the exact name "FIREBASE_TOKEN" in order for Firebase CLI to automatically pick it up without any further configurations.

  2. The most important step here is to install the Firebase CLI on the image running on circleci. To do that we need to add the Firebase installation line to the config.yml file in your project.

We will add the following command as a step to run before we run our fastlane command.

steps:
  - run:
        name: Install Firebase CLI tools
        command: curl -sL firebase.tools | bash
  - run:
        name: Deploy the Fastlane lane
        command: bundle exec fastlane <yourLaneName>

In order for this command to work you need to choose on a linux based machine for your CI. Otherwise you can use a differnet command npm install -g firebase-tools

This concludes our guide. I hope this helps you take the step and migrate to Firebase and setup your automatic distribution using Fastlane and CircleCI.

Amr Saleh amrsalehmail@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment