简体   繁体   English

收到错误java.lang.NoClassDefFoundError:com.google.android.gms.common.GooglePlayServicesUtil

[英]getting error java.lang.NoClassDefFoundError: com.google.android.gms.common.GooglePlayServicesUtil

I know it'a already many questions was like this, I read all of them, and can't find solution anyway. 我知道已经有很多这样的问题,我已经阅读了所有问题,但仍然找不到解决方案。 What i did: 我做了什么:

I did all this steps fine from http://developer.android.com/google/play-services/setup.html#Install to install google play sdk In my project property in Android tab I have "google play service library" ok, in Java Builder Path: "Android Private Libraries" i have google-play-service.jar, and this library are selected. 我从http://developer.android.com/google/play-services/setup.html#Install安装了Google Play sdk后,所有步骤都很好,在Android选项卡中的项目属性中,我有“ Google Play服务库”,在Java Builder路径中:“ Android私有库”我有google-play-service.jar,并且已选择此库。 I did Import lib project also. 我也做了Import lib project。

Code for testing i took from http://developer.android.com/google/gcm/client.html . 我从http://developer.android.com/google/gcm/client.html获取的测试代码。 My manifest file: 我的清单文件:

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

My java code: package lt.vaziouju.vaziuoju; 我的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;
}

}

If you have any idea how I can it, it will be grate. 如果您有任何想法,我将不胜感激。 I know I'm not good enough in android programming, and just started learning GCM but I'm already spend 6h to reading a google, and nothing. 我知道我在android编程上还不够好,刚刚开始学习GCM,但是我已经花了6个小时来阅读Google,什么也没有。

Thanks for any idea. 感谢您的任何想法。

Are you using Eclipse? 您正在使用Eclipse吗? If Eclipse sees a jar file for compilation, it does not necessarily include it into the apk. 如果Eclipse看到要编译的jar文件,则不一定将其包含在apk中。 (You have to mention the jar in several places, and usually people do not remember in how many places.) (您必须在几个地方提到这个罐子,通常人们不记得在几个地方。)

ritht-click on the project name -- build path -- configure build path -- order and export. 右键单击项目名称-构建路径-配置构建路径-订购并导出。

The same dialog has a Projects tab, this is where you specify projects you depend on. 同一对话框中有一个“项目”选项卡,您可以在其中指定所依赖的项目。

If that does not work, put the jar into the libs subdirectory of your project. 如果这样不起作用,请将jar放入项目的libs子目录中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NoClassDefFoundError:设备上的com.google.android.gms.common.GooglePlayServicesUtil - NoClassDefFoundError: com.google.android.gms.common.GooglePlayServicesUtil on device 无法找到com.google.android.gms.common.GooglePlayServicesUtil方法 - Could not find method com.google.android.gms.common.GooglePlayServicesUtil java.lang.NoClassDefFoundError:解析失败:Lcom / google / android / gms / common / GooglePlayServicesUtil - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/GooglePlayServicesUtil GOOGLE PLAY服务例外:com.google.android.gms.common.GooglePlayServicesUtil - GOOGLE PLAY SERVICES EXCEPTION: com.google.android.gms.common.GooglePlayServicesUtil java.lang.NoClassDefFoundError:com.google.android.gms.common.internal.zzbo - java.lang.NoClassDefFoundError: com.google.android.gms.common.internal.zzbo 异常java.lang.NoClassDefFoundError:com.google.android.gms.common.AccountPicker - Exception java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker java.lang.NoClassDefFoundError:com.google.android.gms.gcm.GoogleCloudMessaging使用java.lang.NoClassDefFoundError: - java.lang.NoClassDefFoundError: com.google.android.gms.gcm.GoogleCloudMessaging using java.lang.NoClassDefFoundError: Android错误:java.lang.NoClassDefFoundError:com.google.android.gms.R $ string - Android error: java.lang.NoClassDefFoundError: com.google.android.gms.R$string 运行时错误:java.lang.NoClassDefFoundError:com.google.android.gms.R $ styleable - Run Time Error : java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable Android Google Maps v2:java.lang.NoClassDefFoundError:com.google.android.gms.R $ styleable - Android Google Maps v2: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM