💥 This project will help you distribute your app with the power of Firebase App Distribution and fastlane. As you may know, Firebase App Distribution is a replacement of Beta. This sample also guides you how to organize a multi-build types and a multi-flavor Android application.
- Firebase App Distribution via fastlane
- Tools and components
- To-do list
- Plugins - Bonus*
- Resources
- Find this docs useful?
- License
🔥 Firebase App Distribution makes distributing your apps to trusted testers painless. By getting your apps onto testers' devices quickly, you can get feedback early and often. And, if you use Crashlytics in your apps, you’ll automatically get stability metrics for all your builds, so you know when you’re ready to ship. Please visit Firebase App Distribution page fore more detail.
🚀 fastlane is the easiest way to automate beta deployments and releases for your iOS and Android apps. 🚀 It handles all tedious tasks, like generating screenshots, dealing with code signing, and releasing your application. Please visit fastlane page fore more detail.
This to-do list is consist of 5 sections. We will see how both Firebase and Android side work respectively.
In this part, we will learn how to register our app via Firebase Console.
Before you can add Firebase to your Android app, you need to create a Firebase project to connect to your Android app. Visit Understand Firebase Projects to learn more about Firebase projects.
- In the Firebase console, click Add project, then select or enter a Project name.
- Click Continue.
- Click Create project.
- In the center of the Firebase console's project overview page, click the Android icon to launch the setup workflow.
- Enter your app's application ID in the Android package name field. An application ID is sometimes referred to as a package name (e.g. com.yourcompany.yourproject)
- Enter other app information as prompted by the setup workflow. (SHA-1)
- To get the debug certificate fingerprint, copy and paste below code block into your Terminal:
keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore
- The default password for the debug keystore is android. The keytool then prints the fingerprint to the terminal. For example:
Certificate fingerprint: SHA1: DA:39:A3:EE:5E:6B:4B:0D:32:55:BF:EF:95:60:18:90:AF:D8:07:09
- To get the debug certificate fingerprint, copy and paste below code block into your Terminal:
- Click Register app.
- Add the Firebase Android configuration file to your app:
-
Click Download google-services.json to obtain your Firebase Android config file (google-services.json).
-
Move your config file into the module (app-level) directory of your app. This is not required anymore, hereafter you can move all required info into strings resources. This is explained in the Android side
dependencies { // Add the following line: classpath 'com.google.gms:google-services:4.3.2' // Google Services plugin }
-
In your module (app-level) Gradle file (usually app/build.gradle), add a line to the bottom of the file.
android { } // Add the following line to the bottom of the file: apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
-
- To your module (app-level) Gradle file (usually app/build.gradle), add the dependencies for the Firebase products that you want to use in your app.
dependencies { // ... // Add the Firebase SDK for Google Analytics implementation 'com.google.firebase:firebase-analytics:17.2.1' // Add the SDKs for any other Firebase products you want to use in your app // For example, to use Firebase Authentication and Cloud Firestore implementation 'com.google.firebase:firebase-auth:19.1.0' implementation 'com.google.firebase:firebase-firestore:21.2.1' // Getting a "Could not find" error? Make sure that you've added // Google's Maven repository to your root-level build.gradle file }
- Sync your app to ensure that all dependencies have the necessary versions.
- If you added Analytics, run your app to send verification to Firebase that you've successfully integrated Firebase. Otherwise, you can skip the verification step. Firebase usually needs a verification for distribution so that you need add Analytics and run the app.
In this part, we will configure our Android application to allow it to be in touch with Firebase App Distribution.
When you work on a project that has multiple build types or flavors, you will most likely face weird issues. For example:
Could not find google-services.json while looking in [src/flavor1/debug, src/debug, src/flavor1]
To suppress such error, you have to create both src and all flavor folders and move google-services.json file into each one. This could be costly especially you have several build types and flavors. Now we will see how to use only resources instead of google-services.json file and obtain the same result for our app.
- Add the google-services.json file and the plugin to your project as described in the Add Firebase to your Android Project guide.
- Run
./gradlew :app:assembleDebug
to force the plugin to do its job. - Open the generated file
app/build/generated/res/google-services/debug/values/values.xml
and inspect the contents, it should look something like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<! -- Present in all applications -->
<string name="google_app_id" translatable="false">1:1035469437089:android:73a4fb8297b2cd4f</string>
<! -- Present in applications with the appropriate services configured -->
<string name="gcm_defaultSenderId" translatable="false">1035469437089</string>
<string name="default_web_client_id" translatable="false">337894902146-e4uksm38sne0bqrj6uvkbo4oiu4hvigl.apps.googleusercontent.com</string>
<string name="ga_trackingId" translatable="false">UA-65557217-3</string>
<string name="firebase_database_url" translatable="false">https://example-url.firebaseio.com</string>
<string name="google_api_key" translatable="false">AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8</string>
<string name="google_crash_reporting_api_key" translatable="false">AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8</string>
<string name="project_id" translatable="false">mydemoapp</string>
</resources>
- Copy each of the resources from that file into your app’s own strings.xml file (or any XML resources file you want).
- Remove the google-services plugin from your app and delete the google-services.json file, you don’t need them anymore!
The reason that is underneath this way according to the Firebase docs
Because this provider is just reading resources with known names, another option is to add the string resources directly to your app instead of using the Google Services gradle plugin. You can do this by:
- Removing the google-services plugin from your root build.gradle
- Deleting the google-services.json from your project
- Adding the string resources directly
- Deleting apply plugin: 'com.google.gms.google-services' from your app build.gradle
-
Navigate to your app folder or on Terminal inside Android Studio, type the command below:
sudo gem install fastlane -NV
-
Verify that the installation was successful by typing this command in the CLI:
fastlane -version
-
Run
fastlane init
-
Provide the package name for your application when asked (e.g. com.thedancercodes.fastlanedroid)
-
Press enter when asked for the path to your json secret file
-
Answer ’n’ when asked if you plan on uploading info to Google Play via Fastlane (we can set this up later)
That’s it! Fastlane will automatically generate a configuration for you based on the information provided. This process generates our App file and Fastfile. Below is a screenshot of the Fastlane directory in your project containing these files.
Appfile: Defines configuration information that is global to your app.
Fastfile: Defines different lanes that drive the behavior of fastlane to do different tasks.
The Fastfile defines what steps run & in what order Fastlane runs them. A group of steps is called a lane
Below are code snippets show the contents of the Fastfile & Appfile:
App file | Fast File |
---|---|
There are something we need to add into our Fastfile in order to have lane working correctly.
-
app: This key indicates our APP_ID. This is found on Firebase console. Respectively;
- Click on settings gear icon.
- Scroll down a bit and copy APP_ID.
-
release_notes_file: A file that includes changelog.
-
testers_file: A file that includes testers. If we specify it we can skip Distribute app to testers since fastlane will handle distribution automatically.
-
firebase_cli_path: A path to Firebase CLI - Please see Setup Firebase CLI
-
apk_path: Refers to our apk path that we want to distribute.
📋 The Firebase CLI (GitHub) provides a variety of tools for managing, viewing, and deploying to Firebase projects.
-
Install plugin
firebase_app_distribution
for fastlane by run this in your terminalfastlane add_plugin firebase_app_distribution
-
Check that if in your Pluginfile like this
-
Next, install Firebase CLI by running this in your terminal
curl -sL firebase.tools | bash
-
Sign in your account to authorize Firebase by running
firebase login
-
and you can log out anytime by running with the following command line
firebase logout
-
-
In order to distribute your application, you need to build it first. You can check out fastlane build actions for more options. Below code block is enough to build our application.
gradle( task: "assemble", flavor: "MyFlavor", build_type: "Release" -> This could be Debug or any kind of custom build type. )
-
Now we need to add a fastlane lane to distribute our application. A common lane can look like;
- Final step is to run our lane. It is mentioned as a last step at the end of the docs. Please navigate to Run the lane
We also need to have some settings on Firebase console in order to able to distribute our application such as defining testers, groups, invite links and so on.
- First, navigate to App Distribution section on the console.
- Navigate to Testers & Groups that we can create testers or groups which will receive app updates via App Tester application.
- Simply type target email addresses.
- You can also create invite link to allow new testers to sign up via this custom link
- Rather like you provide your .apk file manually, fastlane will upload apk files to this part when you run the command. Here you can see list of previous distributions and number of invited, accepted and downloaded persons.
When you expand any distribution you will see email addresses which were invited and release notes.
- Most important part, when you upload your apk to Firebase console, you need to manually distribute it to your testers as following:
After you add testers, click Next.
- Click Distribute to N tester.
- Distribution is successful. Now let's check it out on our email. Please navigate to Android Device side
The last part is to download our app after getting an aler email that indicates the application has a new release.
- Open email address that is registered on the console.
- Your email would probably look like;
- Click Download the latest build
- If you don't still install App Tester app, it will probably prompt you to first install it and then receive release.
- Open App Tester app.
- You will probably see a page which look like;
- Click Download
- 🎊 Yay! You have the latest pre_prod release on your device!
💥 Just type below command and our app will be distributed in a while 🎊
fastlane distribute
For a faster execution, you could type:
bundle exec fastlane distribute
...And the result!
increment_version_code is a fastlane plugin that helps to increment version code in each release. This usually is used in Deploy to Play Store part. In this example, I used it in Firebase distribution part to imitate the scenario.
increment_version_code(
gradle_file_path: "./app/build.gradle"
)
Sometimes you might need to checkout a new branch after you distributed your application. In case of that, branch names usually have version name as a suffix to make it clear. get_version_name helps you do so...
An example:
new_version = get_version_name(
gradle_file_path:"./app/build.gradle",
ext_constant_name:"versionName"
)
dotenv basically shims to load environment variables from .env into ENV in development. To install it, just type below command on terminal;
sudo gem install -n /usr/local/bin dotenv
If it asks you some permissions, grant it otherwise it won't continue.
Since we have a sensitive data called Firebase App Id we need to store it in a .env file. Therefore, fastlane will access and read content directly. We need to follow steps below in order;
- Create a .env.secret file inside fastlane folder
- Add
.env.secret
to your.gitignore
file (if you are using git) - Manually load .env.secret in the
before_all block
in yourFastfile
# fastlane/Fastfile
fastlane_require 'dotenv'
before_all do
Dotenv.overload '.env.secret'
end
lane :distribute do
firebase_app_distribution(
app: ENV['FIREBASE_APP_ID'],
...
)
end
That's it! Fastlane will automatically read our value from the file and distribute a release without any error.
Resources that I benefit from to create this comprehensive documentation.
- Firebase App Distribution Page
- Firebase App Distribution and Fastlane, too fast too furious!
- Automating the Android Build and Release Process using Fastlane -Part I
- Fastlane Page
- How to use Firebase on Android without the google-services plugin
- Add Firebase to your Android project
- Increment version code plugin
- Get version name plugin
- carbon.now.sh
Find this docs useful? ❤️
Support it by joining stargazers for this repository. ⭐
And follow me for my next creations! 🤩
Apache License
/*
* Designed and developed by 2019 nuhkoca (Nuh Koca)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/