Could not find method getCompileConfiguration() fo

2019-05-15 09:56发布

问题:

I'm getting the following error.

Could not find method getCompileConfiguration() for arguments [] on object of type com.android.build.gradle.internal.api.ApplicationVariantImpl.

回答1:

I was facing similar issue and after spent some time over internet I found below solution. If you are using latest version of google-services in build.gradle then following changes need to be done :-

1) In project level build.gradle

        buildscript {
            repositories {
                jcenter()
                mavenLocal()
                maven {
                    url 'https://maven.google.com/'
                    name 'Google'
                }
            }
            dependencies {
                classpath 'com.android.tools.build:gradle:3.1.2'
                classpath 'com.google.gms:google-services:3.3.1'
            }
        }

        allprojects {
            repositories {
                jcenter()
                mavenLocal()
                maven {
                    url 'https://maven.google.com/'
                    name 'Google'
                }
            }
        }

2) In App level build.gradle

android{
    //All other
    buildToolsVersion '27.0.3'
    }
        dependencies {
        // All other
            implementation 'com.google.firebase:firebase-database:15.0.1'
        }
        apply plugin: 'com.google.gms.google-services'

3) In gradle-wrapper.properties

distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip



回答2:

we had the same problem... solved by upgrading gradle in gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip

and the gradle plugin in gradle.build

repositories {
    google()
    ...
}

dependencies {
    ...
    classpath 'com.android.tools.build:gradle:3.1.0'
}