Q:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzt;

Please help me to resolve this error.
My application crashes whenever it is installed every first time in device. After reopening the app it is working fine.
  java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzt;
    at com.google.android.gms.gcm.GcmTaskService.onBind(Unknown Source:2)
    at android.app.ActivityThread.handleBindService(ActivityThread.java:3559)
    at android.app.ActivityThread.access$1400(ActivityThread.java:199)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1671)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.util.zzt" on path: DexPathList[[zip file "/data/app/realm.com.realm-d6u0u9PECofXK-J8QnDdVw==/base.apk"],nativeLibraryDirectories=[/data/app/realm.com.realm-d6u0u9PECofXK-J8QnDdVw==/lib/x86, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.google.android.gms.gcm.GcmTaskService.onBind(Unknown Source:2) 
    at android.app.ActivityThread.handleBindService(ActivityThread.java:3559) 
    at android.app.ActivityThread.access$1400(ActivityThread.java:199) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1671) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:193) 
    at android.app.ActivityThread.main(ActivityThread.java:6669) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)  

App level build.gradle
    apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'org.jetbrains.kotlin.android.extensions'

apply plugin: 'io.fabric'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "My application package ID"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 2
        versionName "1.0"
        multiDexEnabled true
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    //Google Place API
    implementation 'com.google.android.gms:play-services-places:16.0.0'
    
    //Google Location API
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    
    //Firebase
    implementation 'com.google.firebase:firebase-messaging:17.4.0'
    
    //QuickBlox
    implementation "com.quickblox:quickblox-android-sdk-messages:3.3.1"
    implementation "com.quickblox:quickblox-android-sdk-chat:3.3.1"
    implementation "com.quickblox:quickblox-android-sdk-content:3.3.1"
    
    //Multidex
    implementation'com.android.support:multidex:1.0.3'
}

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

Project level app.gradle
buildscript {
    ext.kotlin_version = '1.3.21'
    repositories {
        google()
        jcenter()

        //  Crashlytics
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        //Crashlytics
        classpath 'io.fabric.tools:gradle:1.27.1'

    }
}

allprojects {
    repositories {
        google()
        jcenter()
        
        maven {
            url 'https://maven.google.com/'
        }
        maven {
            url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
            
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I am not able to resolve this error. Please let me know what is wrong in the code.
Thank you in advance

A:

As I tried many ways to resolve this error by updating all my play service and firebase Gradle dependency, adding Multidex file but still I was facing the same issue, but after adding below line in my app.gradle. The issue got resolved.
implementation 'com.google.android.gms:play-services-gcm:16.1.0'

