Java.lang.NoClassDefFoundError : Failed resolution of: Lcom/google/android/gms/common/Google PlayServicesUtil error
I’m trying to run the Google Cloud Messaging example, which follows the official tutorial< a href="https://developer.android.com/google/gcm/client.html" rel="noreferrer noopener nofollow" > https://developer.android.com/google/gcm/client.html. However, the example suddenly crashes and generates an error like this:
After tracking, I found that the error with this code is:
/**
* 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 also followed the guide to set up the Google Play Services https://developer.android.com/google/play-services/setup.html So far, I’ve done the following:
- Copy “google-play-services_lib” to your Eclipse workspace.
- Reference “google-play-services_lib” to the sample project.
I’ve done this many times and have been looking for a solution for days and it’s driving me crazy. Please help!!! 🙁
P.S: I was testing with a physical device, tested on my LG G3 and Galaxy S4.
Solution
I
have been trying many solutions and finally I found my own. The solution is as follows.
Change the VM value in \eclipse\eclipse.ini as follows:
Open the file
–launcher. XXMaxPermSize
512M
-showsplash
org.eclipse
–launcher.defaultAction
Open the file
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx1024mFollow https://developer.android.com/google/play-services/setup.html set and reference “google-play-services_lib” in your project. The final output should look similar to the following image:
- Add “google-play-services
- .jar” from “google-play-services_lib/libs” (following step 2, after importing the project into the workspace) to the build path, as shown in the following figure
- Finally, select “google-play-services.jar” in the Order and Export tab of Java Build Path
I
hope this solution helps android developers because it frustrates me since I followed Google’s guide but the app keeps crashing 😀
Cheers