Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need to apply google-services plugin AT THE BOTTOM for Firebase SDK?

EDITED

As @doug-stevenson tells us in his answer, the Firebase dependency declaration does not have to be at the bottom of build.gradle anymore.


On the Firebase SDK setup page, it says,

apply plugin: 'com.android.application'

android {
    // ...
}

dependencies {
  // ...
  compile 'com.google.firebase:firebase-core:9.0.2'
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

Why is that? Does the ordering matter?

like image 470
shoheikawano Avatar asked Jun 23 '16 14:06

shoheikawano


1 Answers

UPDATE: With the latest version of the play services plugin, it is no longer necessary to apply it at the bottom of build.gradle.


It has to do with the way the plugin helps to manage dependencies, and the order of events that Gradle uses to build the project.

The plugin will actually add a dependency on firebase-core if it's not present in your project. It will also check the version of Firebase and Play Services dependencies. However, in order for it to do all this without conflict with other plugins, the Google Services plugin has to run against a project after the project dependencies are already defined. So, applying the plugin after the dependencies block (typically at the bottom of the file) makes all this possible.

The important thing to know is that some projects may experience a version conflict problem if the plugin is at the top. You will avoid these problems by adding it to the bottom.

like image 99
Doug Stevenson Avatar answered Oct 18 '22 21:10

Doug Stevenson