异常 java.lang.NoClassDefFoundError: com.google.android.gms

时间:2023-03-17
本文介绍了异常 java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试来自 Google Drive 的 快速入门:在 Android 上运行 Drive 应用开发工具包.我遵循了漏洞过程,但是当我在我的设备(真实设备)中运行该应用程序时,它会崩溃并出现以下异常:

I'm trying the Quickstart: Run a Drive App on Android from Google Drive SDK. I have followed the hole process, but when I ran the app in my devices (real ones), it crashes with the following exception:

java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker

最后,它在这段代码的第二行指向我的源代码:

And finally, it points to my source in the second line of this code:

credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE);
startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER); // <- This one

我的困惑来自于我已经完成了文章指示我做的所有事情:

My confussion comes from the fact I have done everything the article instructs me to do:

  • 我已生成证书

  • I have generated the certificate

启用 API(使用证书指纹)

Enabled the API (with the certificate fingerprint)

在Eclipse中创建并配置android项目

Created and configurated the android project in Eclipse

  • 添加了带有 Google 插件的 API

复制了样本(我实际上做了复制粘贴)

Copied the sample (I actually did copy-paste)

  • 当然,我更正了包名和类名

  • Ofcourse, I corrected the package and class names

我还添加了应用程序的权限,甚至是其他与帐户相关的权限

Also I added the permissions for the App, even other permissions reffering to acounts

我什至添加了 Google Play Android Developer API 及其权限.

I even added the Google Play Android Developer API and its perimssions.

但是当我运行应用程序时,它仍然崩溃.所有的图书馆似乎都很好.我想知道它是否特定于 Android APIv17,因为我的设备是 APIv10 和 APIv15(我也添加了支持库).

But when I run the App, it still crashes. All the libraries seem to be fine. I wonder if it is specific to Android APIv17, since my devices are APIv10 and APIv15 (I added the support library also).

请帮忙.请原谅我的英语不好.谢谢.

Please, help. And excuse me for my bad english. Thank you.

推荐答案

我在 jtwitter.jar 库中遇到了同样的问题.如果你运行的是 Android Studio,你必须做一个干净的 &构建(AS 目前还没有真正做到这一点).

I had the same issue with the jtwitter.jar library. If you're running Android Studio, you have to do a clean & build (which AS doesn't truly do right now).

转到您的命令行,导航到您的项目根目录并执行 ./gradlew clean

Go to your command line, navigate to your project root and execute ./gradlew clean

在你这样做之前

确保您的 .jar 文件已添加到您的 /libs 文件夹(如果您使用的是 build 17 或更高版本,它必须是 libs,而不是 <代码>库).右键单击并选择添加为库...

Ensure that your .jar file is added to your /libs folder (if you're using build 17 or later, it has to be libs, and not lib). Right-click and select Add as Library...

然后您将不得不编辑您的 build.gradle 文件(位于您的 /src 目录中).

Then you're going to have to edit your build.gradle file (located in your /src directory).

它应该看起来像这样:

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 5
        targetSdkVersion 16
    }
}

dependencies 块更改为如下所示:

Change the dependencies block to look like this:

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('[path/to/.jar]')
}

然后您可以构建并运行您的项目.

Then you can build and run your project.

这篇关于异常 java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:如何将手机号码拆分为国家代码、地区代码和本 下一篇:如何使用 Drive SDK 列出域中的所有 Google 文档?

相关文章

最新文章