ClassNotFoundException找不到类“ com.google.android.gms.common.internal.zzbq

时间:2019-09-05 12:12:43

标签: java android firebase android-gradle-plugin firebase-storage

我必须将文件存储在Firebase存储中。

我的Gradle文件:

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.deadbrains.propertymanagement"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.github.jineshfrancs:CaptchaImageView:1.0'
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.google.firebase:firebase-firestore:11.8.0'
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'
    implementation 'com.google.firebase:firebase-auth:17.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') {
        transitive = true;
    }
}
apply plugin: 'com.google.gms.google-services' 

这是我的build.gradle(项目:应用程序名称):

buildscript {

    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:4.0.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}     

当我上传文件时发生错误。 这是我上传文件的代码

private void uploadFile() {
        if (filePath != null) {
            pDialog = ProgressDialog.show( AddNoticeActivity.this ,"" ,"Wait..." ,false ,false );

            StorageReference riversRef = null;
            if (extension.equals( "docx" ) || extension.equals( "doc" )) {
                Random Number = new Random();
                int Rnumber = Number.nextInt( 100000 );
                String name = "doc" + Rnumber;
                riversRef = FirebaseStorage.getInstance().getReference().child( "Notice/" + name );
            } else if (extension.equals( "pdf" )) {
                Random Number = new Random();
                int Rnumber = Number.nextInt( 100000 );
                String name = "pdf" + Rnumber;
                riversRef = FirebaseStorage.getInstance().getReference().child( "Notice/" + name );
            } else {
                Random Number = new Random();
                int Rnumber = Number.nextInt( 100000 );
                String name = "pic" + Rnumber;
                riversRef = FirebaseStorage.getInstance().getReference().child( "Notice/" + name );
            }
            strAttachment = riversRef.getPath();
            Log.d( "storage path : " ,strAttachment );

            riversRef.putFile( filePath )
                    .addOnSuccessListener( new OnSuccessListener <UploadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                            callAddNoticeService();
                        }
                    } )
                    .addOnFailureListener( new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception exception) {
                            Log.d( "Error" ,exception.getMessage() );
                            Toast.makeText( getApplicationContext() ,exception.getMessage() ,Toast.LENGTH_LONG ).show();
                        }
                    } )
                    .addOnProgressListener( new OnProgressListener <UploadTask.TaskSnapshot>() {
                        @Override
                        public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {

                        }
                    } );
        }
    }

它在第

行显示错误
     riversRef = FirebaseStorage.getInstance().getReference().child( "Notice/" + name );

错误是

  

致命异常:java.lang.NoClassDefFoundError无法解决以下问题:   Lcom / google / android / gms / common / internal / zzbq;

当我升级依赖项时,它显示错误:

  

错误:找不到资源android:attr / fontVariationSettings。   消息{种类=错误,文本=错误:资源   找不到android:attr / fontVariationSettings。

     

错误:找不到资源android:attr / ttcIndex。消息{种类=错误,   text = error:找不到资源android:attr / ttcIndex。

1 个答案:

答案 0 :(得分:2)

升级以下依赖项:

 implementation 'com.google.firebase:firebase-storage:11.8.0'
 implementation 'com.google.firebase:firebase-firestore:11.8.0'
 implementation 'com.google.firebase:firebase-core:16.0.9'
 implementation 'com.google.firebase:firebase-messaging:18.0.0'
 implementation 'com.google.firebase:firebase-auth:17.0.0'

对此:

 implementation 'com.google.firebase:firebase-storage:19.0.0'
 implementation 'com.google.firebase:firebase-firestore:21.0.0'
 implementation 'com.google.firebase:firebase-core:17.2.0'
 implementation 'com.google.firebase:firebase-messaging:20.0.0'
 implementation 'com.google.firebase:firebase-auth:19.0.0'

在以下链接中查看最新版本:

https://firebase.google.com/support/release-notes/android

更新依赖项后,您需要迁移androidx,您可以在以下链接中找到方法:

https://stackoverflow.com/a/57005161/7015400