简体   繁体   English

java.lang.NoClassDefFoundError:解析失败:Lcom / google / android / gms / common / GooglePlayServicesUtil

[英]java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/GooglePlayServicesUtil

I'm trying to run the sample of Google Cloud Messaging, which follows the tutorial from official website https://developer.android.com/google/gcm/client.html . 我正在尝试运行Google Cloud Messaging示例,该示例遵循官方网站https://developer.android.com/google/gcm/client.html上的教程。 However, the sample suddenly crash and generate the error as following: 但是,样本突然崩溃并产生如下错误:

Logcat生成的错误

After tracing, I found the error in this block of code: 跟踪后,我在这段代码中发现了错误:

     /**
     * 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've also followed the guide to set up Google Play Service https://developer.android.com/google/play-services/setup.html and I've done the following so far: 我也按照指南设置了Google Play服务https://developer.android.com/google/play-services/setup.html ,到目前为止我已完成以下操作:

  • Copy the "google-play-services_lib" into Eclipse workspace. 将“google-play-services_lib”复制到Eclipse工作区。
  • Reference the "google-play-services_lib" into the sample project. 将“google-play-services_lib”引用到示例项目中。

引用“google-play-services_lib”

I've done this many times and been searching for solution for a few days now, it is driving me crazy. 我已经做了很多次,现在一直在寻找解决方案,这让我发疯了。 Please HELP!!! 请帮忙!!! :( :(

PS: I'm using physical device to test, tested on my LG G3 and Galaxy S4. PS:我正在使用物理设备进行测试,在我的LG G3和Galaxy S4上进行了测试。

I've been trying on many solution, finally I've come to my own fix. 我一直在尝试很多解决方案,最后我来解决问题。 The solution goes as below. 解决方案如下。

  1. Change your VM values in "\\eclipse\\eclipse.ini" as below: 在“\\ eclipse \\ eclipse.ini”中更改您的VM值,如下所示:

    openFile 打开文件
    --launcher.XXMaxPermSize --launcher.XXMaxPermSize
    512M 512M
    -showsplash -showsplash
    org.eclipse.platform org.eclipse.platform
    --launcher.defaultAction --launcher.defaultAction
    openFile 打开文件
    -vmargs -vmargs
    -Dosgi.requiredJavaVersion=1.5 -Dosgi.requiredJavaVersion = 1.5
    -Xms512m -Xms512m
    -Xmx1024m -Xmx1024m

  2. Follow https://developer.android.com/google/play-services/setup.html to set up and reference the "google-play-services_lib" into your project. 按照https://developer.android.com/google/play-services/setup.html设置并将“google-play-services_lib”引用到您的项目中。 Final output should be something like the image below: 最终输出应该如下图所示:

在此输入图像描述

  1. Add "google-play-services.jar" from "google-play-services_lib/libs" (according to step 2, after you imported the project into your workspace) into your build path as picture below: 将“google-play-services.jar”从“google-play-services_lib / libs”(根据步骤2,将项目导入工作区后)添加到构建路径中,如下图所示:

在此输入图像描述

在此输入图像描述

  1. Finally, check "google-play-services.jar" in "Order and Export" tab of Java Build Path: 最后,检查Java Build Path的“Order and Export”选项卡中的“google-play-services.jar”:

在此输入图像描述

I hope this solution could help fellow android dev, as it got me frustrated since I followed the guide from google, but the app keep crashing :D 我希望这个解决方案可以帮助其他Android开发者,因为它让我感到沮丧,因为我遵循谷歌的指南,但应用程序不断崩溃:D

Cheers 干杯

Check to see if your device has the Google Play Services app installed and also it has the same version as installed in your project. 检查您的设备是否安装了Google Play服务应用,并且其版本与您项目中安装的版本相同。

Also check the minSDK and TargetSDK in the manifest file does not exceed or precede API levels. 另外,检查清单文件中的minSDK和TargetSDK是否超过或超出API级别。

Do not miss this tag in Manifest: 不要错过Manifest中的这个标签:

<application
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application> 

要测试Google Play服务,您需要在安装了Google Play服务的物理设备上运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.NoClassDefFoundError: Failed resolution Failed resolution of: Lcom/google/android/gms/common/internal/zzab; - java.lang.NoClassDefFoundError: Failed resolution Failed resolution of: Lcom/google/android/gms/common/internal/zzab; java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / android / gms / common / internal / zzbo; - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbo; java.lang.NoClassDefFoundError:解析失败:Lcom/google/android/gms/common/util/zzq; - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzq; java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / android / gms / common / GoogleApiAvailabilityLight; - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/GoogleApiAvailabilityLight; 用firebase java.lang.NoClassDefFoundError响应本机:无法解决以下问题:Lcom / google / android / gms / common / internal / zzbq - React Native with firebase java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / android / gms / common / internal / zzbp; - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbp; java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / android / gms / common / internal / zzbq附近的地方应用 - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq Nearby Place App java.lang.NoClassDefFoundError:解析失败:Lcom / google / android / gms / common / util / zzt; - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzt; java.lang.NoClassDefFoundError:解析失败:Lcom/google/android/gms/common/R$string; - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string; 收到错误java.lang.NoClassDefFoundError:com.google.android.gms.common.GooglePlayServicesUtil - getting error java.lang.NoClassDefFoundError: com.google.android.gms.common.GooglePlayServicesUtil
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM