android - 在库模块 : Uknown property 'LibraryVariants' 中使用 Firebase 时出现问题

标签 android firebase gradle

我正在尝试将 Firebase 添加到我的项目中,但我的项目有点特别。 Firebase 将在我的项目的库模块中使用,因此它不会在我的应用程序模块中。

我正在按照指南中添加 Firebase 的手动过程进行操作,但我总是收到此错误:

Uknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension



我在我的项目 gradle 文件中添加了这个:
    buildscript {
  dependencies {
    // Add this line
    classpath 'com.google.gms:google-services:3.1.0'
  }
}

这在我的库模块 gradle 文件中:
    ...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

尝试同步我的项目时出现错误。我也尝试了最后一个 gradle 插件。我也尝试在我的应用程序模块中添加插件,结果相同。我正在使用 Android Studio 3.0。

是什么产生了这个错误?也许 Firebase 与库模块不兼容?

PS:我正在使用 SDK 级别 23 进行编译:
android {
    compileSdkVersion 'Google Inc.:Google APIs:23'
    buildToolsVersion '24.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 20
    }

注意:我知道 Stack Overflow 中回答了有关 LibraryVariants 的问题,但这些问题不适用于我的案例。

最佳答案

google-services 插件不适用于库模块。它仅适用于应用程序模块。

This page在步骤 1 中说:

Open the build.gradle file inside your application module directory.

Note: Android Studio projects contain a top-level build.gradle file and a build.gradle file for each module. Be sure to edit the file for your application module. See Building Your Project with Gradle for more information about Gradle.



This page说:

This step requires that the apply plugin: 'com.google.gms.google-services' line be at the bottom of your app/build.gradle



并且:

The google-services.json file is generally placed in the app/ directory (at the root of the Android Studio app module).

关于android - 在库模块 : Uknown property 'LibraryVariants' 中使用 Firebase 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47291019/

相关文章:

android - 如何从 Firebase 检索所有数据并将其放在 RecyclerView 上

android - Jetpack Compose 实际上适用于类而不是函数?

firebase - 如何使用 CLI 在 Firebase 项目中创建/初始化默认实时数据库实例?

java - 用于具有子项目的项目的 Dropwizard + Gradle fatJar 引入 gradle-api-5.4.1.jar deps

java - 我如何在没有任何依赖项检查的情况下运行 gradle?

java - "The filename or extension is too long error"使用渐变

android - 声明 URL 的正确方法?

android - 程序化 ImageView 和 picasso

swift - 如何更改 iOS 9 中的 Firebase 推送通知内容?

java - 如何从 Firebase 列表中包含的分支获取数据