Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find method com.google.android.gms.common.GooglePlayServicesUtil

I know this question had already a lot of answer and fix...But nothing worked for me...

I'm trying to add the push notification to my android apps. In order to do that, I use the "google-play-services_lib" and the "google-play-services.jar". I followed the tutorial provided by Google Setting Up Google Play Services for Eclipse.

What I did :

  • Installing the Google play services with the SDK Manager in Eclipse
  • Import an Existing Android Code into Workspace (/android-sdks/extras/google/google_play_services/libproject/google-play-services_lib), with the "Copy projects into workspace" checked...Based on what google suggested

    Note: You should be referencing a copy of the library that you copied to your development workspace—you should not reference the library directly from the Android SDK directory.

  • Referencing the library into my project (Right Click -> Properties -> Android -> Library -> Add -> google-play-services_lib)

  • Added a copy of the google-play-services.jar into my projetc libs folder.

  • Adding the jar file to my build path...I had to uncheck the jar files under the Order and export tab to avoid the following error :

    [2014-07-14 09:41:56 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/google/android/gms/internal/a;
    [2014-07-14 09:41:56 ] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/google/android/gms/internal/a;

  • Added the following to my Manifest file :

    <meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
    
  • Creating the pro guard exception

    -keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
    }
    
    -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
     public static final *** NULL;
     }
    
     -keepnames @com.google.android.gms.common.annotation.KeepName class *
     -keepclassmembernames class * {
     @com.google.android.gms.common.annotation.KeepName *;
     }
    
     -keepnames class * implements android.os.Parcelable {
     public static final ** CREATOR;
     }
    

When i try to simply check if the device have the Google Play Service APK with the following

    GooglePlayServicesUtil.isGooglePlayServicesAvailable(this)

I always see this error :

Could not find method com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable, referenced from method com.example.testpush.MainActivity.onCreate

And :

07-14 10:34:53.631: E/AndroidRuntime(421): FATAL EXCEPTION: main
07-14 10:34:53.631: E/AndroidRuntime(421): java.lang.NoClassDefFoundError: com.google.android.gms.common.GooglePlayServicesUtil
07-14 10:34:53.631: E/AndroidRuntime(421):  at com.example.testpush.MainActivity.onCreate(MainActivity.java:16)
07-14 10:34:53.631: E/AndroidRuntime(421):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-14 10:34:53.631: E/AndroidRuntime(421):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-14 10:34:53.631: E/AndroidRuntime(421):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-14 10:34:53.631: E/AndroidRuntime(421):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-14 10:34:53.631: E/AndroidRuntime(421):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-14 10:34:53.631: E/AndroidRuntime(421):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-14 10:34:53.631: E/AndroidRuntime(421):  at android.os.Looper.loop(Looper.java:123)
07-14 10:34:53.631: E/AndroidRuntime(421):  at android.app.ActivityThread.main(ActivityThread.java:3683)
07-14 10:34:53.631: E/AndroidRuntime(421):  at java.lang.reflect.Method.invokeNative(Native Method)
07-14 10:34:53.631: E/AndroidRuntime(421):  at java.lang.reflect.Method.invoke(Method.java:507)
07-14 10:34:53.631: E/AndroidRuntime(421):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-14 10:34:53.631: E/AndroidRuntime(421):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-14 10:34:53.631: E/AndroidRuntime(421):  at dalvik.system.NativeStart.main(Native Method)

Am I missing something here???? Thanks for any idea.

like image 729
gabsao Avatar asked Jul 14 '14 08:07

gabsao


People also ask

Is it possible to check if Google Play Services are installed?

This method is deprecated. Use GoogleApiAvailability.isGooglePlayServicesAvailable (Context) instead. Verifies that Google Play services is installed and enabled on this device, and that the version installed on this device is no older than the one required by this client.

What does isgoogleplayservicesavailable (context) do?

It will direct them to one of the following places to either the Play Store if Google Play services is out of date or missing, or system settings if Google Play services is disabled on the device. error code returned by isGooglePlayServicesAvailable (Context) call.

How do I get error notifications from googleapiavailability?

Use GoogleApiAvailability.showErrorNotification (Context, int) instead. Displays a notification relevant to the provided error code. This method is similar to getErrorDialog (int, android.app.Activity, int), but is provided for background tasks that cannot or shouldn't display dialogs.

What is the use of geterrordialog method in Android?

This method is similar to getErrorDialog (int, android.app.Activity, int), but is provided for background tasks that cannot or shouldn't display dialogs. error code returned by isGooglePlayServicesAvailable (Context) call. If errorCode is ConnectionResult.SUCCESS then null is returned.


1 Answers

I ran into this exact same problem. Started clean eclipse workspace (using ADT 23.0.3.1327240). Downloaded the latest Play Services library (v 5.0.89-000) via SDK Manager. Followed all correct instructions, ans still got linker problems when app is launched.

My solution was to use an older version of Play Serices library (luckily still had v4.4.52-000 of the lib in one of my older projects. Download mine here.) Doing a refresh and clean build after importing this older version seems to solve the problem for now.

Hopefully someone will comment on the logged bug and give us a real solution.

like image 51
Diederik Avatar answered Oct 25 '22 01:10

Diederik