设备上的NoClassDefFoundError:com.google.android.gms.common.GooglePlayServicesUtil

时间:2014-01-23 13:31:50

标签: java android

我有一个用于尝试推送通知的Android应用。 到目前为止,我所拥有的只是一个简单的活动,它启动了以下检查功能:

    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 {
            out("Not Supported!");
            finish();
        }
        return false;
    }
    return true;
    }

这是来自官方教程。

应用程序构建没有错误,但是,当我尝试在模拟器或手机(galaxy S4,android 4.2.2)上运行此检查时,它会抛出NoClassDefFoundError。

这是堆栈跟踪:

    java.lang.IllegalStateException: Could not execute method of the activity
        at android.view.View$1.onClick(View.java:3591)
        at android.view.View.performClick(View.java:4084)
        at android.view.View$PerformClick.run(View.java:16966)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at android.view.View$1.onClick(View.java:3586)
        at android.view.View.performClick(View.java:4084)
        at android.view.View$PerformClick.run(View.java:16966)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.common.GooglePlayServicesUtil
        at com.epam.move.notification.MainActivity.checkPlayServices(MainActivity.java:52)
        at com.epam.move.notification.MainActivity.testClicked(MainActivity.java:41)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at android.view.View$1.onClick(View.java:3586)
        at android.view.View.performClick(View.java:4084)
        at android.view.View$PerformClick.run(View.java:16966)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)

我用Google搜索,据我所知,这意味着我的手机错过了Google服务APK。

我可以告诉我的应用程序在打包时包含它,还是应该在手机上安装一些东西?

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.epam.move.notification"
android:versionCode="1"
android:versionName="1.0" >

<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" />
<uses-permission android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE" />

<!--<permission android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />    -->

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="MoVE.n"
    android:theme="@style/AppTheme" >


    <activity
        android:name="com.epam.move.notification.MainActivity"
        android:label="MoVE.n" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

Gradle构建脚本:

    <?xml version="1.0" encoding="utf-8"?>
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:4.0.30'
}

感谢。

1 个答案:

答案 0 :(得分:0)

我有这个问题...请将SDK中的GooglePlayService项目作为依赖模块包含在您的项目中。这可能有所帮助。该项目的路径是android_sdk \ extras \ google \ google_play_services \ libproject \