Distributing a Flutter App on Firebase with Fastlane for Android | by way of CurlyCoder | Jan, 2024

CurlyCoder

Within the dynamic global of cellular app building, deploying an software successfully is a very powerful for achieving your target audience seamlessly. On this weblog submit, we’ll discover tips on how to distribute a Flutter app on Firebase the use of Fastlane, an impressive device that streamlines the deployment procedure. Fastlane simplifies tedious duties, automates construct and deployment processes, and complements collaboration amongst group participants.

Necessities: Sooner than diving into the deployment procedure, be sure to have the next necessities:

  • A Flutter app in a position for deployment.
  • Firebase venture arrange with the vital configurations.
  • Fastlane put in for your building system.

To arrange Fastlane in your Flutter venture, practice those steps:

  1. Set up Fastlane by way of operating the next command:
gem set up fastlane

Navigate for your Flutter venture listing and run the next command to initialize Fastlane:

fastlane init

All over the initialization procedure, you’ll be triggered to go into your bundle identify. Moreover, input the trail to the name of the game report (.json) related together with your Google Cloud Carrier Account. This provider account must have the next permissions:

  • Proprietor
  • Firebase App Distribution Admin
  • Carrier Account Consumer

This guarantees that Fastlane can have interaction with Firebase and carry out the vital deployment duties.

Including Fastlane Plugins

To strengthen Fastlane’s features for Flutter and Firebase deployment, upload the next plugins:

fastlane add_plugin firebase_app_distribution flutter git_switch_branch

This command provides the firebase_app_distribution, flutter, and git_switch_branch plugins for your Fastlane configuration.

Configuring Fastlane for Firebase Deployment

Subsequent, configure Fastlane to deploy your Flutter app to Firebase. Open the Fastfile within the ‘fastlane’ listing and upload lane for Firebase deployment for Android platform:

platform :android do
lane :deploy_to_firebase do
# Upload Firebase deployment instructions right here
finish
finish

Change the feedback with the vital Firebase deployment instructions for Android platform.

Upload Firebase distribution configurations for your ‘fastlane/Fastfile’:

default_platform(:android)

platform :android do
before_all do
ENV["FIREBASE_LOGIN_CREDENTIALS"] = "PATH_TO_YOUR_JSON_KEY"
ENV["FIREBASE_APP_ID"] = "YOUR_ANDROID_APP_ID"
ENV["FIREBASE_TOKEN"] = "YOUR_FIREBASE_CLI_TOKEN"
finish

lane :deploy_to_firebase do |choices|
# Firebase App Distribution for Android
except choices[:branch].nil?
git_switch_branch(department: choices[:branch])
git_pull
finish
flutter(args: %(blank))
flutter(args: %w[pub get])
output_file = flutter_build(
construct: 'appbundle',
)
firebase_app_distribution(
app: ENV["FIREBASE_APP_ID"],
android_artifact_type: 'AAB',
android_artifact_path: 'PATH_TO_APPBUNDLE',
release_notes: "Fastlane Construct",
teams: 'YOUR_TESTERS_GROUP_NAME',
firebase_cli_token: ENV["FIREBASE_TOKEN"],
service_credentials_file: ENV["FIREBASE_LOGIN_CREDENTIALS"]
)
finish
finish

Change “YOUR_ANDROID_APP_ID” together with your Android app package ID.

Including Firebase CLI Token

Create a Firebase CLI Token the use of the next command:

firebase login:ci

This command will instructed you to log in and generate a Firebase CLI token, which is very important for authentication all the way through the deployment procedure.

Acquiring the JSON Key Report for Firebase

Sooner than you’ll deploy your Flutter app to Firebase, download a JSON key report for authentication by way of following those steps:

  1. Cross to the Firebase Console: Open your internet browser and navigate to the Firebase Console.
  2. Make a choice Your Mission: If you have already got a Firebase venture, make a choice it from the record. If no longer, create a brand new venture.
  3. Navigate to Mission Settings: Click on at the tools icon (settings) within the left-hand navigation menu to visit “Mission settings.”
  4. Carrier accounts: Within the Mission settings, navigate to the “Carrier accounts” tab.
  5. Generate New Personal Key: Scroll all the way down to the “Firebase Admin SDK” phase and click on on “Generate new personal key.”
  6. Obtain the JSON Key Report: After clicking “Generate new personal key,” the important thing might be downloaded as a JSON report.
  7. Securely Retailer the JSON Key Report: The JSON key report comprises delicate data and must be treated with care. Remember to retailer it securely and steer clear of exposing it to your model regulate machine. It’s a just right apply so as to add the JSON key report for your venture in a location this is excluded from model regulate (e.g., upload it for your venture’s .gitignore report).
  8. Referencing the JSON Key Report in Fastlane: Within the Appfile of your Fastlane configuration, use the json_key_file approach to specify the trail to the JSON key report:
json_key_file("trail/to/your/firebase/credentials.json")

Change “trail/to/your/firebase/credentials.json” with the true trail for your downloaded JSON key report.

Setup firebase app distribution thru API:

  1. Open the Cloud Console: Cross to the Google Cloud Console.
  2. Make a choice a Mission: Be sure to are running inside of the right kind Google Cloud venture. You’ll be able to make a choice your venture from the venture drop-down menu on the best of the web page.
  3. Open the API Library: Within the left-hand navigation pane, click on on “APIs & Services and products” after which make a choice “Library.”
  4. To find the API: Use the quest bar to search out the “Firebase App Distribution API” to permit.
  5. Allow the API: Click on at the API you need to permit, and at the subsequent web page, click on the “Allow” button.

Now, you’ll set up apps thru API. To validate your json_key_file run the next command:

fastlane run validate_play_store_json_key json_key:"trail/to/your/firebase/credentials.json"

Deploying Your Flutter App to Firebase: Now that Fastlane is configured, deploying your Flutter app to Firebase is a breeze. Run the next command:

fastlane deploy_to_firebase

Fastlane will execute the desired Firebase deployment instructions for Android platform. Observe the deployment development within the console, and as soon as finished, your Flutter app might be to be had for distribution thru Firebase App Distribution.

fastlane deploy_to_firebase department:BRANCH_NAME

This command specifies the department (BRANCH_NAME on this case) that you need to deploy. You’ll be able to exchange BRANCH_NAME with the identify of your required department. That is in particular helpful when you’ve got other branches for building, staging, or manufacturing, permitting you to deploy particular branches as wanted.

Automating the deployment procedure is very important for keeping up a streamlined and environment friendly building workflow. By way of integrating Fastlane into your Flutter venture and configuring it for Firebase deployment, you’ll be certain a continuing and hassle-free distribution procedure. Fastlane empowers builders to concentrate on construction nice apps whilst automating the tedious duties related to deployment. Satisfied coding!

Leave a Comment

Your email address will not be published. Required fields are marked *