8

I'm developing an app that uses GoogleAPIClient to (obviously) get the user current location in background.

For this task I use IntentService with WakefulBroadcastReceiver (to get the location every hour). Everything was working fine on development environment but when deployed in Play Store some devices are getting this error:

Fatal Exception: java.lang.NoClassDefFoundError: com/google/android/gms/internal/zzsa
       at com.google.android.gms.common.api.GoogleApiClient$Builder.<init>(Unknown Source)
       at tellerina.com.br.vivara.services.MyService.onHandleIntent(MyService.java:37)
       at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:157)
       at android.os.HandlerThread.run(HandlerThread.java:61)

I have searched the internet for answers but I didn't find anything. Here's the point where the exception appears:

mGoogleApiClient = new GoogleApiClient.Builder(MyApplication.getContext())
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();

Thanks a lot!

EDIT

app build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.21.2'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "app.package"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 9
        versionName "1.5.2"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile fileTree(dir: 'libs', include: ['*.so'])
    compile(project(':volley')) {
        exclude module: 'support-v4'
    }
    compile files('libs/commons-codec-1.9.jar')
    compile('com.navercorp.volleyextensions:volley-views:2.0.+') {
        exclude module: 'library'
    }
    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
    }
    compile 'com.android.support:appcompat-v7:23+'
    compile 'com.android.support:cardview-v7:23+'
    compile 'com.android.support:recyclerview-v7:23+'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'io.card:android-sdk:5.1.1'
    compile 'com.github.ksoichiro:androidpagecontrol:0.1.1'
    compile 'me.relex:circleindicator:1.1.5@aar'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.easing:library:1.0.1@aar'
    compile 'com.daimajia.androidanimations:library:1.1.3@aar'
    compile 'com.facebook.android:facebook-android-sdk:4.5.0'
    compile 'br.com.jansenfelipe:androidmask:1.0.1'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:design:23+'
    compile 'com.squareup.picasso:picasso:2.5.2'
}
apply plugin: 'com.google.gms.google-services'

Root project build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.google.gms:google-services:+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

EDIT 2

Using Fabric, now I can see that all of users affected by this problem is using Android 4.x. Maybe the distribution of Play Services is bugged, I don't know. But it's decreasing the number of devices with this error.

Elvis Oliveira
  • 941
  • 2
  • 15
  • 29

3 Answers3

2

You are getting

Fatal Exception: java.lang.NoClassDefFoundError: com/google/android/gms/internal/zzsa at com.google.android.gms.common.api.GoogleApiClient$Builder.(Unknown Source)

NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time.

OLD

 dependencies {
   // classpath 'com.android.tools.build:gradle:1.5.0'
   // classpath 'com.google.gms:google-services:+' //(Avoid Calling "+")


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

GoogleApiClient is used with a variety of static methods. Some of these methods require that GoogleApiClient be connected, some will queue up calls before GoogleApiClient is connected;

mGoogleApiClient = new GoogleApiClient.Builder(this)

You should try with your build.gradle

Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-beta2'
        classpath 'com.google.gms:google-services:2.0.0-beta2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Advice you can call

  1. compile 'com.android.support:appcompat-v7:23.1.1' instead of v7:23+

Then Clean-Rebuild-Restart-Sync Your Project .Hope this helps .

Edit

The Android build system consists of an Android plugin for Gradle. Gradle is an advanced build toolkit that manages dependencies and allows you to define custom build logic. Android Studio uses a Gradle wrapper to fully integrate the Android plugin for Gradle. The Android plugin for Gradle also runs independent of Android Studio.

A plugin is simply any class that implements the Plugin interface. Gradle provides the core plugins as part of its distribution so simply applying the plugin as above is all you need to do.

with beta2 and alpha-5 gradle dosen't show error. But without "apply plugin: 'services'" and 'classpath' it's not generated gcm_defaultSenderId for GCM

You can check Get an Instance ID

You should use apply plugin .

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    Hey man, with beta2 and alpha-5 gradle dosen't show error. But without "apply plugin: 'services'" and 'classpath' it's not generated gcm_defaultSenderId for GCM – Elvis Oliveira Feb 15 '16 at 11:51
  • 1
    Yes!! With this conf no more devices (even with Android 4.x) is getting this error! Thanks a lot for help me! I think that I have make a mistake the other time I use this conf, but know its OK! – Elvis Oliveira Feb 17 '16 at 16:16
0

This is clearly a proguard configuration error of gms (Google Play Services).

  • Either it's caused by a wrong version that you build against, and you can build against another one.
  • Or it's caused by the Play Services installed on the device, and you can only hope that the Play Services team has stopped roolout of this version until the bug is fixed.
rds
  • 26,253
  • 19
  • 107
  • 134
  • Using Fabric, now I can see that all of users affected by this problem is using Android 4.x. Maybe the distribution of Play Services is bugged, I don't know. But it's decreasing the number of devices with this error. – Elvis Oliveira Feb 15 '16 at 11:54
0

FINALLY! I spent literally several hours trying to resolve this issue, maybe it has already been resolved but it turns out any of the google classes you use have to all be the SAME VERSION in the gradle, i.e.

   compile 'com.google.android.gms:play-services-identity:7.8.0'

compile 'com.google.android.gms:play-services-location:7.5.0'

I was calling two different versions. Once I chanced it to this:

   compile 'com.google.android.gms:play-services-identity:7.8.0'

compile 'com.google.android.gms:play-services-location:7.8.0'

the classdeferror was resolved!

JenniferG
  • 602
  • 1
  • 5
  • 13