gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 15:11:14 25 4
gpt4 key购买 nike

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

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

谢谢。

最佳答案

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

关于java - 设备上的 NoClassDefFoundError : com. google.android.gms.common.GooglePlayServicesUtil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21309629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com