简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM