我正在尝试将 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/