Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

  • Enabled the API (with the certificate fingerprint)

  • Created and configurated the android project in Eclipse

    • Added the APIs with the Google plugin
  • 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

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

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.

like image 350
aBarocio80 Avatar asked Dec 26 '22 05:12

aBarocio80


1 Answers

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

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

BEFORE YOU DO THIS

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

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

It should look something like this:

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

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.

like image 118
Matt Avatar answered Apr 05 '23 23:04

Matt