[英]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:
但是,样本突然崩溃并产生如下错误:
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 ,到目前为止我已完成以下操作:
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.
解决方案如下。
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
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:
最终输出应该如下图所示:
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.