Java.lang.NoClassDefFoundError : Failed resolution of: Lcom/google/android/gms/common/Google PlayServicesUtil error

Java.lang.NoClassDefFoundError : Failed resolution of: Lcom/google/android/gms/common/Google PlayServicesUtil error … here is a solution to the problem.

Java.lang.NoClassDefFoundError : Failed resolution of: Lcom/google/android/gms/common/Google PlayServicesUtil error

I’m trying to run the Google Cloud Messaging example, which follows the official tutorial< a href="https://developer.android.com/google/gcm/client.html" rel="noreferrer noopener nofollow" > https://developer.android.com/google/gcm/client.html. However, the example suddenly crashes and generates an error like this:

Error Generated by Logcat

After tracking, I found that the error with this code is:

     /**
     * Check the device to make sure it has the Google Play Services APK. If
     * it doesn't, display a dialog that allows users to download the APK from
     * the Google Play Store or enable it in the device's system settings.
     */
    private boolean checkPlayServices() {
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (resultCode != ConnectionResult.SUCCESS) {
            if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
                GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                        PLAY_SERVICES_RESOLUTION_REQUEST).show();
            } else {
                Log.i(TAG, "This device is not supported.");
                finish();
            }
            return false;
        }
        return true;
    }

I also followed the guide to set up the Google Play Services https://developer.android.com/google/play-services/setup.html So far, I’ve done the following:

  • Copy “google-play-services_lib” to your Eclipse workspace.
  • Reference “google-play-services_lib” to the sample project.

Referencing "google-play-services_lib"

I’ve done this many times and have been looking for a solution for days and it’s driving me crazy. Please help!!! 🙁

P.S: I was testing with a physical device, tested on my LG G3 and Galaxy S4.

Solution

I

have been trying many solutions and finally I found my own. The solution is as follows.

  1. Change the VM value in \eclipse\eclipse.ini as follows:

    Open the file
    –launcher. XXMaxPermSize
    512M
    -showsplash
    org.eclipse
    –launcher.defaultAction
    Open the file
    -vmargs
    -Dosgi.requiredJavaVersion=1.5
    -Xms512m
    -Xmx1024m

  2. Follow https://developer.android.com/google/play-services/setup.html set and reference “google-play-services_lib” in your project. The final output should look similar to the following image:

enter image description here

    Add “google-play-services

  1. .jar” from “google-play-services_lib/libs” (following step 2, after importing the project into the workspace) to the build path, as shown in the following figure

enter image description here

enter image description here

  1. Finally, select “google-play-services.jar” in the Order and Export tab of Java Build Path

enter image description here

I

hope this solution helps android developers because it frustrates me since I followed Google’s guide but the app keeps crashing 😀

Cheers

Related Problems and Solutions

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

Java.lang.NoClassDefFoundError : Failed resolution of: Lcom/google/android/gms/common/util/zzt; mistake … here is a solution to the problem.

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

Please help me fix this error.

My app crashes every time I install it for the first time in my device. After reopening the app, it works 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)  

Application-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 can’t fix this error. Please let me know what’s wrong with the code.
Thanks in advance

Solution

Because I tried a lot of ways to fix this error, by updating all my playback services and firebase gradle dependencies, adding Multidex files, but I’m still facing the same issue, but after adding the following line in my app.gradle. The problem has been resolved.

implementation 'com.google.android.gms:play-services-gcm:16.1.0'

Related Problems and Solutions