为什么我们需要在底部安装适用于Firebase SDK的google-services插件? [英] Why do we need to apply google-services plugin AT THE BOTTOM for Firebase SDK?

查看:86
本文介绍了为什么我们需要在底部安装适用于Firebase SDK的google-services插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已编辑

@ doug-stevenson在回答中告诉我们,Firebase依赖声明不必不再位于build.gradle的底部.

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

Firebase SDK设置页面上,

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?

推荐答案

更新:使用最新版本的Play服务插件,不再需要在构建底部应用它.摇动.

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

这与插件帮助管理依赖项的方式以及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.

如果您的项目中不存在该插件,则该插件实际上将添加对firebase-core的依赖.它还将检查Firebase和Play Services依赖项的版本.但是,为了使其完成所有这些操作而不会与其他插件发生冲突,必须在定义项目依赖项后 对一个项目运行Google Services插件.因此,在依赖项块之后(通常在文件底部)应用插件将使所有这些事情成为可能.

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.

这篇关于为什么我们需要在底部安装适用于Firebase SDK的google-services插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆