Andrey Grigoryev
Andrey Grigoryev

Reputation: 61

error "No such property: applicationVariants for class: java.lang.String" when connecting the plugin "com.google.gms.google-services"

I am using the latest version of Android Studio and all plugins. I am trying to connect android app to firebase console. Successfully downloaded google-services.json file and added to module root directory. Added lines "classpath 'com.google.gms: google-services: 4.3.3" and "apply plugin:' com.google.gms.google-services'" to the build.gradle files.

build.gradle project level:

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath 'com.google.gms:google-services:4.3.3'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

build.gradle app level:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "app"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 42
        versionName "16.0.2"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {

        checkReleaseBuilds false

    }
}

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'androidx.navigation:navigation-fragment:2.3.0'
    implementation 'androidx.navigation:navigation-ui:2.3.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    // CloudPayments SDK
    implementation 'ru.cloudpayments.android:sdk:1.0.5'
    // add the Firebase SDK for Google Analytics
    implementation 'com.google.firebase:firebase-iid:20.2.4'
    implementation 'com.google.firebase:firebase-messaging:20.2.4'
    implementation 'com.google.firebase:firebase-analytics:17.5.0'

}

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

When synchronizing the project, I get the error

No such property: applicationVariants for class: java.lang.String

which refers to the line "apply plugin: 'com.google.gms.google-services'" in build.gradle app level.

I ask for advice on how you can fix this error.

Upvotes: 6

Views: 801

Answers (1)

Lady Bugger
Lady Bugger

Reputation: 1

I solved this by checking all my gradle files and found out that, the gradle.properties file has some errors in it. I don’t know how they got there. But I replaced the file contents by copying the contents from a fresh android project. Solved

Upvotes: 0

Related Questions