2013-11-27 86 views
2

我知道已經有很多問題是這樣的,我閱讀了所有這些問題,無論如何也找不到解決方案。我所做的:出現錯誤java.lang.NoClassDefFoundError:com.google.android.gms.common.GooglePlayServicesUtil

我這一切是幾步之遙http://developer.android.com/google/play-services/setup.html#Install精細安裝谷歌玩SDK 在Android的標籤我的項目屬性我有「谷歌遊戲服務庫」確定,在Java構建路徑:「Android的私家藏書」我有谷歌播放service.jar,並選擇了這個庫。我也做了導入lib項目。

測試代碼我從http://developer.android.com/google/gcm/client.html。 我的清單文件:

<uses-sdk 
    android:minSdkVersion="9" 
    android:targetSdkVersion="19" /> 

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="com.google.android.c2dm.intent.RECEIVE" /> 

<permission 
    android:name="lt.vaziouju.vaziuoju.permission.C2D_MESSAGE" 
    android:protectionLevel="signature" /> 

<uses-permission android:name="lt.vaziouju.vaziuoju.permission.C2D_MESSAGE" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 

    <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="api key here" /> 

    <receiver 
     android:name="lt.vaziouju.vaziuoju.GcmBroadcastReceiver" 
     android:permission="lt.vaziouju.vaziuoju.c2dm.permission.SEND" > 
     <intent-filter> 
      <action android:name="lt.vaziouju.vaziuoju.c2dm.intent.RECEIVE" /> 

      <category android:name="lt.vaziouju.vaziuoju" /> 
     </intent-filter> 
    </receiver> 

    <service android:name="lt.vaziouju.vaziuoju.GcmIntentService" /> 

    <activity 
     ... 
    </activity> 
</application> 

我的Java代碼: 包lt.vaziouju.vaziuoju;

import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Menu; 
import android.widget.TextView; 

import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.GooglePlayServicesUtil; 


public class Test_GCM extends Activity { 

private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000; 
private static final String TAG = null; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_test__gcm); 

    TextView mDisplay = (TextView) findViewById(R.id.display); 

    Context context = getApplicationContext(); 

    // Check device for Play Services APK. 
    if (checkPlayServices()) { 
     // If this check succeeds, proceed with normal processing. 
     // Otherwise, prompt user to get valid Play Services APK. 
    } 
} 

// You need to do the Play Services APK check here too. 
@Override 
protected void onResume() { 
    super.onResume(); 
    checkPlayServices(); 
} 

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

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.test__gcm, menu); 
    return true; 
} 

} 

如果你有任何想法我可以做到這一點,它將是篦。我知道我在android編程方面不夠好,剛開始學習GCM,但我已經花了6個小時閱讀谷歌,沒有。

謝謝你的任何想法。

+0

什麼是你的問題。解釋一下。 –

+0

請發佈您的完整logcat錯誤。還要解釋你面臨的問題? – GrIsHu

回答

3

您使用的是Eclipse嗎?如果Eclipse看到一個用於編譯的jar文件,它不一定會將其包含到apk中。 (你必須在幾個地方提到罐子,通常人們不記得在多少地方。)

ritht點擊項目名稱 - 構建路徑 - 配置構建路徑 - 訂單和導出。

相同的對話框有一個「項目」選項卡,這是指定您依賴的項目的位置。

如果這不起作用,請將jar放入項目的libs子目錄中。

+0

謝謝,我正在使用eclipse。我在我的lib文件夾中缺少jar文件。現在我得到了另一個錯誤,一般項目錯誤「您的項目包含錯誤,請修復......」。當我在屬性 - > Java構建路徑 - >訂單和導出Android專用庫中取消選擇時,我可以運行我的項目,在設備上很好,但在模擬器上我收到警告「Google Play服務不受您的設備支持。」任何想法爲什麼? –

+3

有人知道如何解決在Android Studio中的錯誤..我不會看到像ecclipse中的任何選項。 – lintu