簡體   English   中英

無法找到com.google.android.gms.common.GooglePlayServicesUtil方法

[英]Could not find method com.google.android.gms.common.GooglePlayServicesUtil

我知道這個問題已經有很多答案和解決方法......但是沒有什么對我有用......

我正在嘗試將推送通知添加到我的Android應用程序中。 為此,我使用“google-play-services_lib”和“google-play-services.jar”。 我按照谷歌設置Google Play Services for Eclipse提供的教程。

我做了什么 :

  • 使用Eclipse中的SDK Manager安裝Google Play服務
  • 將現有的Android代碼導入Workspace(/ android-sdks / extras / google / google_play_services / libproject / google-play-services_lib),選中“將項目復制到工作區”...根據谷歌的建議

    注意:您應該引用復制到開發工作區的庫的副本 - 不應直接從Android SDK目錄引用庫。

  • 將庫引用到我的項目中(右鍵單擊 - >屬性 - > Android - >庫 - >添加 - > google-play-services_lib)

  • 在我的projetc libs文件夾中添加了google-play-services.jar的副本。

  • 將jar文件添加到我的構建路徑...我必須取消選中Order and export選項卡下的jar文件以避免以下錯誤:

    [2014-07-14 09:41:56 - Dex Loader]無法執行dex:多個dex文件定義Lcom / google / android / gms / internal / a;
    [2014-07-14 09:41:56]轉換為Dalvik格式失敗:無法執行dex:多個dex文件定義Lcom / google / android / gms / internal / a;

  • 在我的清單文件中添加了以下內容:

     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> 
  • 創建專業保護例外

     -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; } 

當我嘗試簡單地檢查設備是否具有以下的Google Play服務APK時

    GooglePlayServicesUtil.isGooglePlayServicesAvailable(this)

我總是看到這個錯誤:

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

而且:

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)

我在這里遺漏了什么???? 謝謝你的想法。

我遇到了同樣的問題。 開始清理eclipse工作區(使用ADT 23.0.3.1327240)。 通過SDK Manager下載最新的Play服務庫(v 5.0.89-000)。 遵循所有正確的說明 ,當應用程序啟動時仍然會出現鏈接器問題。

我的解決方案是使用較舊版本的Play Serices庫(幸運的是在我的一個舊項目中仍然使用了v4.4.52-000的lib。 在這里下載我的 。)在導入這個舊版本后進行刷新和清理構建似乎解決了現在的問題。

希望有人會評論已記錄的錯誤並給我們一個真正的解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM