unknown property 'LibraryVariants' in build.gradle

佐手、 提交于 2019-11-28 07:20:00

问题


I have the error below in build.gradle at this line:

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

Error:(56, 0) Could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension.

It happened after I installed Firebase.

How to solve this?


回答1:


Add the following to the @project level gradle file:

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

Add the following to the @app level gradle file:

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

Apply plugin

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



回答2:


The error message, Error: Could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension, indicates that this plugin needs to be applied to a module which uses the com.android.application plugin.

So, the simple solution is to only include the google-services plugin in your application module and not your library module:

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



回答3:


I had the same problem and solved it updating gradle and google-services versions.

// 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
}


来源:https://stackoverflow.com/questions/44884400/unknown-property-libraryvariants-in-build-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!