loading...

Exploring Firebase Bill of Materials (BoM)

rosariopfernandes profile image Rosário Pereira Fernandes ・3 min read

Portuguese version available in developingwith.firebaseapp.com

Once upon a time, in a not so distant past, one could easily add the Firebase SDK to their Android Project not worrying about different versions for each module. Every module (core, auth, firestore, storage, etc) would use the same version, so our build.gradle (app) file would look like this:

    implementation 'com.google.firebase:firebase-core:12.0.0'
    implementation 'com.google.firebase:firebase-firestore:12.0.0'
    implementation 'com.google.firebase:firebase-auth:12.0.0'

Or even better, we could declare the firebase version in the build.gradle (project):

buildscript {
    ext.firebase_version = '12.0.0'
    // ... Other configurations
}

and then use it in the build.gradle (app):

    implementation 'com.google.firebase:firebase-core:$firebase_version'
    implementation 'com.google.firebase:firebase-firestore:$firebase_version'
    implementation 'com.google.firebase:firebase-auth:$firebase_version'

But the happiness in this Kingdom didn't last long. After some time, some modules started getting updates more frequently than others, forcing the sdk developers to bump their versions and thus having different versions for each module.

Well, if you wish you had lived in that fairy-tale, I have good news for you! Thanks to the feature Bills of Material (BoM) introduced in Gradle 5.0 you can now use a single version for all the Firebase Android SDK modules.

Bills of Material (BoM) allows the SDK developers to specify (in a bill) which module versions are known to work with each other and then set a version to this bill.

So every time the Firebase Team publishes a new bill, you can be sure that you'll be using the latest versions(at time the BoM was published) of every module.

You can find the latest BoM version in the Firebase Android Release Notes.


Getting Started

Upgrading to Gradle 5.0

Since the BoM feature was introduced in gradle 5.0, you'll probably want to upgrade your gradle version (if you haven't already).

To upgrade to gradle 5.0 and add Firebase BoM to your Android Project, follow these steps:

  1. Upgrade to version 4.10 first and check for any errors deprecation warnings. It's better to fix all errors and warnings before upgrading to a newer version.

  2. Upgrade to version 5.0 using this command in your project root folder:

./gradlew wrapper --gradle-version 5.0
  1. Sync your project and add the dependencies to your gradle file:
dependencies {
    // Import the BoM
    implementation platform('com.google.firebase:firebase-bom:16.0.0')

    // Import the modules not minding their versions. Hooray!
    implementation 'com.google.firebase:firebase-core'
    implementation 'com.google.firebase:firebase-firestore'
    implementation 'com.google.firebase:firebase-auth'

    // ... Other dependencies
}

One more project sync and that's it! You no longer need to worry about different versions for each module.

With Gradle 4.6.x or higher

If you're not planning to upgrade to Gradle 5.0, you can still take advantage of this feature, because it has been in experimental mode since gradle 4.6.x, you just need to enable it:

  1. Open your project's settings.gradle file and add the line enableFeaturePreview('IMPROVED_POM_SUPPORT'):
include ':app'
enableFeaturePreview('IMPROVED_POM_SUPPORT')
  1. Sync your project and add the dependencies to your gradle file:
dependencies {
    // Import the BoM
    implementation 'com.google.firebase:firebase-bom:16.0.0'

    // Import the modules not minding their versions. Hooray!
    implementation 'com.google.firebase:firebase-core'
    implementation 'com.google.firebase:firebase-firestore'
    implementation 'com.google.firebase:firebase-auth'

    // ... Other dependencies
}

One more project sync and that's it!


Notes

Please note that:

  • If you specify a module version and you use a Firebase BoM, then the specified module version overrides the version contained in the BoM.

  • Firebase BoM is still an experimental feature, which means there might be some issues. If you want to report an issue or provide feedback, consider doing so in the Firebase Android SDK Issue Tracker.

Posted on by:

rosariopfernandes profile

Rosário Pereira Fernandes

@rosariopfernandes

Associate Android Developer; Computer Engineering Student; Firebase App Developer and Community Leader at GDG Maputo.

Discussion

markdown guide