【问题标题】:unknown property 'LibraryVariants' in build.gradlebuild.gradle 中的未知属性“LibraryVariants”
【发布时间】:2017-07-03 11:27:35
【问题描述】:

我在 build.gradle 的这一行出现以下错误:

apply plugin: 'com.google.gms.google-services' 

错误:(56, 0) 无法为 com.android.build.gradle.LibraryExtension 类型的对象获取未知属性“LibraryVariants”。

这是在我安装 Firebase 之后发生的。

如何解决?

【问题讨论】:

标签: android android-studio build.gradle


【解决方案1】:

错误消息,Error: could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension,表明这个插件需要应用到一个模块使用com.android.application 插件。

因此,简单的解决方案是仅在您的应用程序模块中包含 google-services 插件,而在您的库模块中:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

【讨论】:

    【解决方案2】:

    我遇到了同样的问题并解决了更新 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
    }
    

    【讨论】:

    • 谢谢。 Google 的 gcm 站点将 com.google.gms:google-services:3.1.0 列为所需版本,但 3.1.1 是固定版本。它还要求在编译后发布apply plugin: 'com.google.gms.google-services' 以进行身份​​验证。
    【解决方案3】:

    将以下内容添加到@project 级别的 gradle 文件中:

    classpath 'com.android.tools.build:gradle:1.3.0'
    classpath 'com.google.gms:google-services:3.0.0'
    

    将以下内容添加到@app 级别的 gradle 文件中:

    // Dependency for Google Sign-In
    compile 'com.google.android.gms:play-services-auth:9.4.0'
    

    应用插件

    apply plugin: 'com.google.gms.google-services'
    

    【讨论】:

    • 我在项目级别有classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.google.gms:google-services:3.1.0',在模块级别有compile 'com.google.android.gms:play-services-auth:11.2.0'apply plugin: 'com.google.gms.google-services',但仍然存在该错误。你能帮忙吗?
    • @EvgeniyPhilippov 你有什么解决办法吗?因为我也有同样的问题。
    猜你喜欢
    • 2017-10-29
    • 1970-01-01
    • 2018-09-07
    • 2023-01-04
    • 2019-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    相关资源
    最近更新 更多