Why am I getting AbstractDynamicObject$CustomMessageMissingMethodException error?

AndroidFirebaseGradle

Android Problem Overview


I have just started a new project and am trying to connect to Firebase.

As soon as I try to build my project I got the error:

>Could not parse the Android application Module's Gradle Config

So I looked in my build which told me that jCenter() was deprecated and that I should remove it. When I removed it, everything worked fine. However, when I tried to connect to Firebase I got the error:

> AbstractDynamicObject$CustomMessageMissingMethodException.

What may be causing this?

Full stack trace:

    Caused by: java.lang.RuntimeException: com.android.build.gradle.internal.crash.ExternalApiUsageException: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method setVariantDir() for arguments [debug] on task ':app:processDebugGoogleServices' of type com.google.gms.googleservices.GoogleServicesTask.
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:71)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:54)
	at com.android.build.gradle.internal.profile.AnalyticsResourceManager.recordBlockAtConfiguration(AnalyticsResourceManager.kt:206)
	at com.android.build.gradle.internal.profile.AnalyticsConfiguratorService.recordBlock(AnalyticsConfiguratorService.kt:85)
	at com.android.build.gradle.internal.plugins.BasePlugin.lambda$createTasks$9(BasePlugin.java:582)
	at com.android.build.gradle.internal.crash.CrashReporting$afterEvaluate$1.execute(crash_reporting.kt:37)
	at com.android.build.gradle.internal.crash.CrashReporting$afterEvaluate$1.execute(crash_reporting.kt)

Android Solutions


Solution 1 - Android

I came here because I am getting the same error. Luckily I was updating dependencies when it happened and narrowed it down to:

classpath 'com.google.gms:google-services:4.3.6'

Change it to

classpath 'com.google.gms:google-services:4.3.5'

The error goes away for me. Hopefully for you too

Here is more info on my dependencies.

Running Android Studio 4.2 build April 28 2021

repositories {
        google()
        mavenCentral()
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0'
        classpath 'com.google.gms:google-services:4.3.5'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.0'
        classpath 'com.google.firebase:perf-plugin:1.4.0'

Gradle Plugin 4.2.0 Gradle 7.0.1

//Firebase
    implementation 'com.google.firebase:firebase-ads:20.1.0'
    implementation 'com.google.firebase:firebase-core:19.0.0'
    implementation 'com.google.firebase:firebase-crash:16.2.1'
    implementation 'com.google.firebase:firebase-messaging:22.0.0'
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
    implementation 'com.google.firebase:firebase-auth:21.0.0'
    implementation 'com.google.firebase:firebase-firestore:23.0.0'

Solution 2 - Android

Update : Google has just fixed the problem in version 4.3.8 (Release Notes)

An updated version of the google-services plugin for Android (v4.3.8) is now available. For more information, see the Firebase Android SDK Release Notes.


The error came from classpath 'com.google.gms:google-services:4.3.6'

The easiest solution :

Go back to version 4.3.5

dependencies {
        classpath 'com.google.gms:google-services:4.3.5'
}

Instead of 4.3.6

dependencies {
        classpath 'com.google.gms:google-services:4.3.6'
}

> In fact, version 4.3.6 is responsible for this error. The easiest > way is to go back to the previous version until it is fixed

Solution 3 - Android

> Caused by: java.lang.RuntimeException: > com.android.build.gradle.internal.crash.ExternalApiUsageException: > org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: > Could not find method setVariantDir()

Fixed bug

You should use the latest possible version.

DO

dependencies {
       
        classpath 'com.google.gms:google-services:4.3.8' 

    }

Solution 4 - Android

Addition to RRiven fix, I started getting error Plugin with id ‘maven’ not found after RRiven fix.

I fixed it with downgrading gradle version to 6.9 from file -> project structure -> project -> gradle version

Solution 5 - Android

Set Code in build.gradle(Project)

classpath 'com.android.tools.build:gradle:4.2.0'

classpath 'com.google.gms:google-services:4.3.5'

Set Line in gradle-wrapper

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

Solution 6 - Android

Best way. Google has resolved it.

    classpath 'com.google.gms:google-services:4.3.8'

Go to the latest version now of 4.3.8

https://developers.google.com/android/guides/releases https://firebase.google.com/support/release-notes/android#google-services_plugin_v4-3-8

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCodingChapView Question on Stackoverflow
Solution 1 - AndroidRRiVENView Answer on Stackoverflow
Solution 2 - AndroidKab AgoudaView Answer on Stackoverflow
Solution 3 - AndroidIntelliJ AmiyaView Answer on Stackoverflow
Solution 4 - AndroidNikhil bhatiaView Answer on Stackoverflow
Solution 5 - AndroidMark NashatView Answer on Stackoverflow
Solution 6 - AndroidNafis KabboView Answer on Stackoverflow