Lesson 3 - Register Firebase and configure Fastlane to push APK to Firebase Distribution (Test version)

03/02/2023 - 3 phút

Follow  on Google News

Summary

The concept

  • Firebase is a Google-powered application development software that allows developers to develop iOS, Android, and web applications. Firebase provides tools to track analytics, report and fix app issues, and create marketing and product tests.

  • APK stands for Android Package (sometimes Android Package Kit or Android Application Package ). It’s the file format Android uses to distribute and install apps. Therefore, APK contains all the elements that an app needs to install correctly on your device.

  • IPA is an extension to the iOS App Store package file which is an application archive file used to distribute applications on iOS. IPA contains files in uncompressed form, which can only be installed on iOS.

Instruct

Sign up for Firebase

After successfully logging in, select “Add Project

  • Enter the project name, here I will name it “React Native DevOps
  • Continue clicking Continue
  • Continue clicking Continue
  • In this step, we choose a GA account or create a new account for GA, then click “Create project”
  • Continue clicking Continue, So you have successfully created the project on Firebase

Configure Firebase for Android

  • Create an App Name for the Android project by clicking the Android icon on the Firebase dashboard page
  • Enter Android package name and click “Register app
  • Download the file google-services.json and click “Next
  • Copy the downloaded file to the android/app folder
  • Then open Android studio and select your project
  • To make google-services.json configuration values accessible to the Firebase SDK, you need the Google Services Gradle plugin.
  • Then, in the module (app-level) build.gradle file, add both the google services plugin and any Firebase SDKs you want to use in your app:
  • Keep coming back to the website and click “Next
  • Continue back to the website and click “Continue console
  • So I have successfully created Firebase for Android

Fastlane configuration for Android

First go to the android folder:

cd android

then init fastlane with command

fastlane init

After successful init, there will be a fastlane folder and 2 files “Appfile” , “Fastfile

Install firebase-tools to get login token

  npm i firebase-tools -g

After I successfully installed and used the command to get the login token

firebase login:ci

So I have a login token

1//0gP2yENNqCT1oCgYIARAAGBASNwF-L9IrqQI9gih5h73FSmaozzyn0HSQXxS7Vyyav2h4zEk4ClMbgmz6CwbEShz_qJVMmTxiGas

Continuing, I will get the app-id

1:320882145170:android:21837959d5ffc9fe65b34b

Continue to update “Appfile”, “Fastfile

  • Appfile
json_key_file("") # Path to the json secret file - Follow https://docs.fastlane.tools/actions/supply/#setup to get one
package_name("com.reactnativedevops") # e.g. com.krausefx.app
  • Fastfile
default_platform(:android)
  desc "Submit a new Beta Build to Crashlytics Beta"
  lane :beta do

    gradle(
      task: "clean"
    )

    gradle(
      task: 'assemble', #assemble #bundle
      build_type: 'Release'
    )

     firebase_app_distribution(
       app: "1:320882145170:android:21837959d5ffc9fe65b34b",
       firebase_cli_token: "1//0gP2yENNqCT1oCgYIARAAGBASNwF-L9IrqQI9gih5h73FSmaozzyn0HSQXxS7Vyyav2h4zEk4ClMbgmz6CwbEShz_qJVMmTxiGas",
     )
  end
end

Continue adding plugins for fastlane

fastlane add_plugin firebase_app_distribution

Enable Firebase Distribution on the Firebase console:

Then we use the command to build

cd android && fastlane beta

When the build is successful, go to the Firebase console page to check if the build is up or not

So the build has been built successfully, now I just need to add the tester’s email to test the Android build

You can refer to github