Android GoogleAPIClient - NoClassDefFoundError: com/google/android/gms/internal/zzsa
Android GoogleAPIClient - NoClassDefFoundError: com/google/android/gms/internal/zzsa
我正在开发一个使用 GoogleAPIClient 来(显然)在后台获取用户当前位置的应用程序。
对于此任务,我将 IntentService 与 WakefulBroadcastReceiver 结合使用(每小时获取一次位置)。在开发环境中一切正常,但在 Play 商店中部署时,某些设备出现此错误:
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)
我在互联网上搜索了答案,但没有找到任何答案。这是出现异常的地方:
mGoogleApiClient = new GoogleApiClient.Builder(MyApplication.getContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
非常感谢!
编辑
应用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'
根项目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()
}
}
编辑 2
使用 Fabric,现在我可以看到所有受此问题影响的用户都在使用 Android 4.x。也许 Play Services 的分发有问题,我不知道。但它正在减少出现此错误的设备数量。
这显然是 gms (Google Play Services) 的 proguard 配置错误。
- 要么是你构建的版本错误导致的,你可以针对另一个版本构建。
- 或者是设备上安装的Play Services导致的,只能希望Play Services团队停止更新这个版本,直到bug修复。
您正在获得
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 当Java 虚拟机 无法在运行时找到在编译时可用的特定 class。
旧
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)
你应该试试你的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()
}
}
建议
你可以打电话给
compile 'com.android.support:appcompat-v7:23.1.1'
而不是
v7:23+
然后Clean-Rebuild-Restart-Sync Your Project
。希望对您有帮助。
编辑
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.
插件就是任何实现插件接口的class。 Gradle 提供核心插件作为其分发的一部分,因此您只需像上面那样应用插件即可。
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
你可以查看Get an Instance ID
你应该使用应用插件 .
终于!我花了好几个小时试图解决这个问题,也许它已经解决了,但事实证明你使用的任何 google 类 都必须是 gradle 中的相同版本, 即
compile 'com.google.android.gms:play-services-identity:7.8.0'
compile 'com.google.android.gms:play-services-location:7.5.0'
我调用了两个不同的版本。一旦我碰巧遇到这个:
compile 'com.google.android.gms:play-services-identity:7.8.0'
compile 'com.google.android.gms:play-services-location:7.8.0'
类错误已解决!
我正在开发一个使用 GoogleAPIClient 来(显然)在后台获取用户当前位置的应用程序。
对于此任务,我将 IntentService 与 WakefulBroadcastReceiver 结合使用(每小时获取一次位置)。在开发环境中一切正常,但在 Play 商店中部署时,某些设备出现此错误:
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)
我在互联网上搜索了答案,但没有找到任何答案。这是出现异常的地方:
mGoogleApiClient = new GoogleApiClient.Builder(MyApplication.getContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
非常感谢!
编辑
应用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'
根项目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()
}
}
编辑 2
使用 Fabric,现在我可以看到所有受此问题影响的用户都在使用 Android 4.x。也许 Play Services 的分发有问题,我不知道。但它正在减少出现此错误的设备数量。
这显然是 gms (Google Play Services) 的 proguard 配置错误。
- 要么是你构建的版本错误导致的,你可以针对另一个版本构建。
- 或者是设备上安装的Play Services导致的,只能希望Play Services团队停止更新这个版本,直到bug修复。
您正在获得
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 当Java 虚拟机 无法在运行时找到在编译时可用的特定 class。
旧
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)
你应该试试你的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()
}
}
建议 你可以打电话给
compile 'com.android.support:appcompat-v7:23.1.1'
而不是v7:23+
然后Clean-Rebuild-Restart-Sync Your Project
。希望对您有帮助。
编辑
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.
插件就是任何实现插件接口的class。 Gradle 提供核心插件作为其分发的一部分,因此您只需像上面那样应用插件即可。
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
你可以查看Get an Instance ID
你应该使用应用插件 .
终于!我花了好几个小时试图解决这个问题,也许它已经解决了,但事实证明你使用的任何 google 类 都必须是 gradle 中的相同版本, 即
compile 'com.google.android.gms:play-services-identity:7.8.0'
compile 'com.google.android.gms:play-services-location:7.5.0'
我调用了两个不同的版本。一旦我碰巧遇到这个:
compile 'com.google.android.gms:play-services-identity:7.8.0'
compile 'com.google.android.gms:play-services-location:7.8.0'
类错误已解决!