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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30378411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:38:58  来源:igfitidea点击:

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

javaandroideclipsegoogle-cloud-messaging

提问by thyzz

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. However, the sample suddenly crash and generate the error as following:

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

Error Generated by Logcat

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.htmland 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.
  • Reference the "google-play-services_lib" into the sample project.
  • 将“google-play-services_lib”复制到 Eclipse 工作区中。
  • 将“google-play-services_lib”引用到示例项目中。

Referencing "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!!! :(

我已经这样做了很多次,并且几天来一直在寻找解决方案,这让我发疯了。请帮忙!!!:(

P.S: I'm using physical device to test, tested on my LG G3 and Galaxy S4.

PS:我正在使用物理设备进行测试,在我的 LG G3 和 Galaxy S4 上进行了测试。

采纳答案by thyzz

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:

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

  2. Follow https://developer.android.com/google/play-services/setup.htmlto set up and reference the "google-play-services_lib" into your project. Final output should be something like the image below:

  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”引用到您的项目中。最终输出应类似于下图:

enter image description here

在此处输入图片说明

  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:
  1. 将“google-play-services_lib/libs”中的“google-play-services.jar”(根据第2步,将项目导入工作区后)添加到构建路径中,如下图:

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

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

enter image description here

在此处输入图片说明

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

干杯

回答by AniV

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> 

回答by Oliver Hemsted

To test Google Play Services you'll need to be running on a physical device with Google Play Services installed.

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