简体   繁体   English

Google云端硬盘通话导致Android应用崩溃

[英]Google Drive call causes Android app to crash

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. 我正在开发一个具有Google云端硬盘的Android应用,但是即使编译正常,在尝试执行任何操作时也会崩溃。

This is a pre-existing, it hasn't been worked on in and was originally an Eclipse project. 这是一个预先存在的东西,尚未进行处理,最初是Eclipse项目。 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. 有人报告已导入Android Studio并修复了该错误,但是当我尝试对Google云端硬盘执行任何操作时,出现以下应用崩溃。

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. 它的credential = ...导致崩溃。

Below is my build.gradle file 以下是我的build.gradle文件

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

}

Update 更新

I've found there is was a jar library I was missing. 我发现有一个我缺少的jar库。 I've added this jar called google-collect-1.0.jar and rebuilt. 我添加了一个名为google-collect-1.0.jar的jar,并对其进行了重建。 When I run the above code it now works and I get a list of Google accounts that I select. 当我运行上面的代码时,它现在可以工作,并且我会选择一个Google帐户。 However, when it then tries to do something with Drive I now get a different error. 但是,当它随后尝试对Drive进行操作时,我现在遇到了另一个错误。

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: getDriveService如下:

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

Update 2 更新2

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 以下是我的gradle文件的外观

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 下面是我的libs目录包含的屏幕截图

项目库目录

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();

I have finally figured out a solution. 我终于找到了解决方案。 Below is a screenshot of the libraries in my libs folder 下面是我的libs文件夹中的库的屏幕截图

libs文件夹

Below is my gradle file 以下是我的gradle文件

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') {

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM