【问题标题】:java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/GooglePlayServicesUtiljava.lang.NoClassDefFoundError:解析失败:Lcom/google/android/gms/common/GooglePlayServicesUtil
【发布时间】:2015-08-03 09:31:44
【问题描述】:

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

经过追踪,发现这块代码的错误:

     /**
     * 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”引用到示例项目中。

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

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

【问题讨论】:

  • 在模拟器或物理设备上运行?
  • 哦...我忘了提,物理设备...抱歉试图简化 n 使问题易于理解@JayeshElamgodil

标签: java android eclipse google-cloud-messaging


【解决方案1】:

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

  1. 如下更改“\eclipse\eclipse.ini”中的 VM 值:

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

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

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

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

我希望这个解决方案可以帮助其他 android 开发者,因为我按照谷歌的指南操作让我很沮丧,但是应用程序不断崩溃:D

干杯

【讨论】:

  • 但是当我在 Java Build Path 的“Order and Export”选项卡中检查“google-play-services.jar”时,出现“Java heap Space”错误。当我从 Java Build Path 中取消选中这个 jar 时,我的应用程序由于未找到 GooglePlayServicesUtil 而崩溃。我也替换了 eclipse.ini 设置的值。请帮我解决一下?
  • @Mohini 在我更改“eclipse.ini”之前,我也遇到了堆空间错误。你能在评论中复制你的“eclipse.ini”文件吗?
  • -启动插件/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar --launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200。 v20140116-2212 -product org.eclipse.epp.package.modeling.product --launcher.defaultAction openFile --launcher.XXMaxPermSize 1048M -showsplash org.eclipse.platform --launcher.XXMaxPermSize 1048M --launcher.defaultAction openFile --launcher .appendVmargs --vmargs -VM_ARGS="-XX:-UseParallelGC -XX:-UseConcMarkSweepGC -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass -Dosgi.classloader.lock=classname -XX:+HeapDumpOnOutOfMemoryError"
  • -Dosgi.requiredJavaVersion=1.6 -Xverify:none -XX:+UseParallelGC -XX:-UseConcMarkSweepGC -XX:PermSize=128m -XX:MaxPermSize=512M -XX:MaxNewSize=128m -XX:NewSize =128m -Xms512M -Xmx1048M
  • @Mohini 似乎您已经更改了我发布的“eclipse.ini”。也许你应该升级你的 Eclipse,因为我使用的是 Eclipse Luna。哦,别忘了在你下载了更高版本的 Eclipse 之后更改“eclipse.ini”。对不起,我帮不了你:(
【解决方案2】:

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

还要检查清单文件中的 minSDK 和 TargetSDK 是否超过或超过 API 级别。

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

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

【讨论】:

  • 感谢@AniV 的回复。但是我在我提到的 2 台物理设备上进行了测试,预装了 Google Play Services 应用程序。清单中的 minSDK 和 targetSDK 应该与我发布的错误日志中的错误没有任何关系。正如我所提到的,我遵循了谷歌的官方指南,因此我没有错过标签。
【解决方案3】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-24
    • 2019-06-25
    • 2018-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 2019-04-13
    相关资源
    最近更新 更多