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

时间:2015-05-21 15:41:13

标签: java android eclipse google-cloud-messaging

我正在尝试运行Google Cloud Messaging示例,该示例遵循官方网站https://developer.android.com/google/gcm/client.html的教程。但是,样本突然崩溃并产生如下错误:

Error Generated by Logcat

跟踪后,我在这段代码中发现了错误:

     /**
     * 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;
    }

我也按照指南设置了Google Play服务https://developer.android.com/google/play-services/setup.html,到目前为止我已完成以下操作:

  • 将“google-play-services_lib”复制到Eclipse工作区。
  • 将“google-play-services_lib”引用到示例项目中。

Referencing "google-play-services_lib"

我已经这么做了很多次,现在一直在寻找解决方案,这让我发疯了。请帮忙!!! :(

P.S:我正在使用物理设备进行测试,在LG G3和Galaxy S4上进行测试。

3 个答案:

答案 0 :(得分:1)

我一直在尝试很多解决方案,最后我自己解决了问题。解决方法如下。

  1. 在“\ eclipse \ eclipse.ini”中更改您的VM值,如下所示:

    中openFile
    --launcher.XXMaxPermSize
    512M
    -showsplash
    org.eclipse.platform
    --launcher.defaultAction
    中openFile
    -vmargs
    -Dosgi.requiredJavaVersion = 1.5
    -Xms512m
    -Xmx1024m

  2. 按照https://developer.android.com/google/play-services/setup.html设置并将“google-play-services_lib”引用到您的项目中。最终输出应该如下图所示:

  3. enter image description here

    1. 将“google-play-services.jar”从“google-play-services_lib / libs”(根据步骤2,将项目导入工作区后)添加到构建路径中,如下图所示:
    2. enter image description here

      enter image description here

      1. 最后,在“Java构建路径”的“订购和导出”标签中查看“google-play-services.jar”:
      2. enter image description here

        我希望这个解决方案可以帮助其他Android开发者,因为它让我感到沮丧,因为我从谷歌的指南,但应用程序不断崩溃:D

        干杯

答案 1 :(得分:0)

检查您的设备是否安装了Google Play服务应用,并且其版本与您项目中安装的版本相同。

同时检查清单文件中的minSDK和TargetSDK是否超出或超出API级别。

不要错过Manifest中的这个标签:

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

答案 2 :(得分:-2)

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