Reputation: 36205
I am working on an Android app which has Google Drive but even though it compiles fine it crashes when I try and do anything.
This is a pre-existing, it hasn't been worked on in and was originally an Eclipse project. Someone reported so imported into Android Studio and fixed the bug however when I try and do anything with Google Drive I get the following app crash.
Process: com.BoardiesITSolutions.PasswordManager, PID: 23121
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/base/Preconditions;
at com.google.api.client.googleapis.extensions.android.accounts.GoogleAccountManager.<init>(GoogleAccountManager.java:41)
at com.google.api.client.googleapis.extensions.android.accounts.GoogleAccountManager.<init>(GoogleAccountManager.java:48)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.<init>(GoogleAccountCredential.java:78)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.usingOAuth2(GoogleAccountCredential.java:97)
at com.BoardiesITSolutions.PasswordManager.Settings$SynchronisationSettings.enableGoogleDrive(Settings.java:575)
at com.BoardiesITSolutions.PasswordManager.Settings$SynchronisationSettings.access$000(Settings.java:420)
at com.BoardiesITSolutions.PasswordManager.Settings$SynchronisationSettings$1.onPreferenceChange(Settings.java:510)
at android.preference.Preference.callChangeListener(Preference.java:928)
at android.preference.ListPreference.onDialogClosed(ListPreference.java:281)
at android.preference.DialogPreference.onDismiss(DialogPreference.java:391)
at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1257)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.common.base.Preconditions" on path: DexPathList[[zip file "/data/app/com.BoardiesITSolutions.PasswordManager-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.google.api.client.googleapis.extensions.android.accounts.GoogleAccountManager.<init>(GoogleAccountManager.java:41)
at com.google.api.client.googleapis.extensions.android.accounts.GoogleAccountManager.<init>(GoogleAccountManager.java:48)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.<init>(GoogleAccountCredential.java:78)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.usingOAuth2(GoogleAccountCredential.java:97)
at com.BoardiesITSolutions.PasswordManager.Settings$SynchronisationSettings.enableGoogleDrive(Settings.java:575)
at com.BoardiesITSolutions.PasswordManager.Settings$SynchronisationSettings.access$000(Settings.java:420)
at com.BoardiesITSolutions.PasswordManager.Settings$SynchronisationSettings$1.onPreferenceChange(Settings.java:510)
at android.preference.Preference.callChangeListener(Preference.java:928)
at android.preference.ListPreference.onDialogClosed(ListPreference.java:281)
at android.preference.DialogPreference.onDismiss(DialogPreference.java:391)
at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1257)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Suppressed: java.lang.ClassNotFoundException: com.google.common.base.Preconditions
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 19 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Below is the part of the code that crashes:
private void enableGoogleDrive()
{
credential = GoogleAccountCredential.usingOAuth2(context, DriveScopes.DRIVE);
startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
}
Its the credential = ...
that is causing the crash.
Below is my build.gradle file
apply plugin: 'com.android.application'
android {
compileOptions.encoding = 'ISO-8859-1'
compileSdkVersion 21
buildToolsVersion "21.1.2"
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId "com.BoardiesITSolutions.PasswordManager"
minSdkVersion 14
targetSdkVersion 21
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_5
targetCompatibility JavaVersion.VERSION_1_5
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
repositories {
mavenLocal()
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.google.android.gms:play-services:7.0.0') {
exclude module: 'support-v4'
}
compile files('libs/commons-codec-1.4.jar');
compile files('libs/google-api-services-drive-v2-rev30-1.12.0-beta.jar')
compile ('com.android.support:appcompat-v7:21.0.0') {
exclude module: 'support-v4'
}
//compile 'com.android.support:support-v4:21.0.0'
compile ('com.BoardiesITSolutions:CritiMon:1.0') {
exclude module: 'support-v4'
}
compile ('com.BoardiesITSolutions:Library:1.1') {
exclude module: 'support-v4'
}
}
I've found there is was a jar library I was missing. I've added this jar called google-collect-1.0.jar and rebuilt. When I run the above code it now works and I get a list of Google accounts that I select. However, when it then tries to do something with Drive I now get a different error.
FileList file = service.files().list().execute();
On the above line is what causes the crash. service is created by calling
credential.setSelectedAccountName(settings.getString("google_drive_account_name", ""));
Drive service = getDriveService(credential);
getDriveService is as follows:
private Drive getDriveService(GoogleAccountCredential credential)
{
return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
}
The error I now get is:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/primitives/UnsignedInteger;
at com.google.api.client.util.Data.<clinit>(Data.java:81)
at com.google.api.client.util.FieldInfo.<init>(FieldInfo.java:131)
at com.google.api.client.util.FieldInfo.of(FieldInfo.java:104)
at com.google.api.client.util.ClassInfo.<init>(ClassInfo.java:174)
at com.google.api.client.util.ClassInfo.of(ClassInfo.java:92)
at com.google.api.client.util.GenericData.<init>(GenericData.java:79)
at com.google.api.client.util.GenericData.<init>(GenericData.java:61)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.<init>(AbstractGoogleClientRequest.java:101)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.<init>(AbstractGoogleJsonClientRequest.java:57)
at com.google.api.services.drive.DriveRequest.<init>(DriveRequest.java:51)
at com.google.api.services.drive.Drive$Files$List.<init>(Drive.java:2914)
at com.google.api.services.drive.Drive$Files.list(Drive.java:2904)
at com.BoardiesITSolutions.PasswordManager.Classes.DriveSync$1.run(DriveSync.java:137)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.common.primitives.UnsignedInteger" on path: DexPathList[[zip file "/data/app/com.BoardiesITSolutions.PasswordManager-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.google.api.client.util.Data.<clinit>(Data.java:81)
at com.google.api.client.util.FieldInfo.<init>(FieldInfo.java:131)
at com.google.api.client.util.FieldInfo.of(FieldInfo.java:104)
at com.google.api.client.util.ClassInfo.<init>(ClassInfo.java:174)
at com.google.api.client.util.ClassInfo.of(ClassInfo.java:92)
at com.google.api.client.util.GenericData.<init>(GenericData.java:79)
at com.google.api.client.util.GenericData.<init>(GenericData.java:61)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.<init>(AbstractGoogleClientRequest.java:101)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.<init>(AbstractGoogleJsonClientRequest.java:57)
at com.google.api.services.drive.DriveRequest.<init>(DriveRequest.java:51)
at com.google.api.services.drive.Drive$Files$List.<init>(Drive.java:2914)
at com.google.api.services.drive.Drive$Files.list(Drive.java:2904)
at com.BoardiesITSolutions.PasswordManager.Classes.DriveSync$1.run(DriveSync.java:137)
at java.lang.Thread.run(Thread.java:818)
Suppressed: java.lang.ClassNotFoundException: com.google.common.primitives.UnsignedInteger
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
I think I have made some progress but I'm still getting a crash although different now.
Below is how my gradle file now looks
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'com.android.application'
android {
compileOptions.encoding = 'ISO-8859-1'
compileSdkVersion 21
buildToolsVersion "21.1.2"
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'README'
exclude 'com.google.api.client.json.JsonFactory.class'
//exclude 'GwtCompatible.class'
/*exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/notice.txt'
exclude 'com.google.api.client.auth.oauth2.AuthorizationCodeFlow.class'
}
defaultConfig {
applicationId "com.BoardiesITSolutions.PasswordManager"
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
repositories {
mavenLocal()
mavenCentral()
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.google.android.gms:play-services:7.0.0') {
exclude module: 'support-v4'
}
compile('com.google.http-client:google-http-client:1.18.0-rc') {
exclude group: 'xpp3'
exclude group: 'org.apache.httpcomponents'
exclude group: 'junit'
exclude group: 'com.google.android'
}
compile('com.google.http-client:google-http-client-jackson2:1.18.0-rc')
compile('com.android.support:appcompat-v7:21.0.0') {
exclude module: 'support-v4'
}
compile('com.BoardiesITSolutions:CritiMon:1.0') {
exclude module: 'support-v4'
}
compile('com.BoardiesITSolutions:Library:1.1') {
}
compile ('com.google.api-client:google-api-client-android:1.18.0-rc') {
}
compile ('com.google.http-client:google-http-client-gson:1.18.0-rc') {
}
}
Below is a screenshot of what my libs directory contains
The error that I am now getting is:
Process: com.BoardiesITSolutions.PasswordManager, PID: 25495
java.lang.NoSuchMethodError: No direct method <init>(Lcom/google/api/client/http/HttpTransport;Lcom/google/api/client/http/HttpRequestInitializer;Ljava/lang/String;Ljava/lang/String;Lcom/google/api/client/json/JsonObjectParser;Lcom/google/api/client/googleapis/services/GoogleClientRequestInitializer;Ljava/lang/String;Z)V in class Lcom/google/api/client/googleapis/services/json/AbstractGoogleJsonClient; or its super classes (declaration of 'com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient' appears in /data/app/com.BoardiesITSolutions.PasswordManager-2/base.apk)
at com.google.api.services.drive.Drive.<init>(Drive.java:135)
at com.google.api.services.drive.Drive$Builder.build(Drive.java:6542)
at com.BoardiesITSolutions.PasswordManager.Classes.DriveSync.getDriveService(DriveSync.java:365)
at com.BoardiesITSolutions.PasswordManager.Classes.DriveSync.access$000(DriveSync.java:65)
at com.BoardiesITSolutions.PasswordManager.Classes.DriveSync$1.run(DriveSync.java:134)
at java.lang.Thread.run(Thread.java:818)
I cannot see what is wrong with this at all, everything I try seems to result in the same problem. Everything compiles fine its just when the code executes it crashes.
The line that it crashes on now is below:
return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
Upvotes: 1
Views: 2059
Reputation: 36205
I have finally figured out a solution. Below is a screenshot of the libraries in my libs folder
Below is my gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'com.android.application'
android {
compileOptions.encoding = 'ISO-8859-1'
compileSdkVersion 21
buildToolsVersion "21.1.2"
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'com.google.gson.JsonSerializer'
exclude 'constant-values.html'
exclude 'overview-summary.html'
exclude 'package-list'
exclude 'overview-tree.html'
exclude 'allclasses-frame.html'
exclude 'allclasses-noframe.html'
exclude 'stylesheet.css'
exclude 'index-all.html'
exclude 'deprecated-list.html'
exclude 'index.html'
exclude 'overview-frame.html'
exclude 'help-doc.html'
}
defaultConfig {
applicationId "com.BoardiesITSolutions.PasswordManager"
minSdkVersion 14
targetSdkVersion 21
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
repositories {
mavenLocal()
mavenCentral()
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
compile ('com.google.android.gms:play-services-ads:7.0.0') {
exclude module: 'support-v4'
}
compile ('com.google.android.gms:play-services-drive:7.0.0') {
exclude module: 'support-v4'
}
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.google.android.gms:play-services:7.0.0') {
exclude module: 'support-v4'
}
compile 'com.google.guava:guava:17.0'
compile('com.android.support:appcompat-v7:21.0.0') {
exclude module: 'support-v4'
}
compile('com.BoardiesITSolutions:CritiMon:1.0') {
exclude module: 'support-v4'
}
compile('com.BoardiesITSolutions:Library:1.1') {
}
}
Upvotes: 1