我在此行的build.gradle中有以下错误:
apply plugin: 'com.google.gms.google-services'
错误:(56,0)无法为com.android.build.gradle.LibraryExtension类型的对象获取未知属性“LibraryVariants”。
安装完Firebase后发生了这件事。
如何解决这个问题?
答案 0 :(得分:7)
错误消息错误:无法获取com.android.build.gradle.LibraryExtension类型的对象的未知属性'LibraryVariants',表示此插件需要应用于模块使用com.android.application
插件。
因此,简单的解决方案是仅在您的应用程序模块中包含google-services插件,而不您的库模块:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
答案 1 :(得分:4)
我遇到了同样的问题并解决了更新gradle和google-services版本的问题。
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
答案 2 :(得分:2)
将以下内容添加到@project级别gradle文件:
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:3.0.0'
将以下内容添加到@app level gradle文件中:
// Dependency for Google Sign-In
compile 'com.google.android.gms:play-services-auth:9.4.0'
申请插件
apply plugin: 'com.google.gms.google-services'