错误:(15、55)错误:无法访问com.google.android.gms.common.internal.safeparcel.zza的zza类文件

时间:2018-09-05 07:18:08

标签: android firebase firebase-cloud-messaging build.gradle

这是我的build.gradle应用程序文件:

dependencies {
    //picture library
    compile 'com.github.bumptech.glide:glide:3.8.0'
    //recycler and card view
    compile 'com.android.support:support-v4:26.+'
    compile 'com.android.support:recyclerview-v7:26.+'
    compile 'com.android.support:cardview-v7:26.+'

    //json
    compile 'com.google.code.gson:gson:2.8.5'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.4.0'
    //firebase
    compile 'com.google.firebase:firebase-core:16.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

这是我的build.gradle项目文件

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

        classpath 'com.google.gms:google-services:4.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()

        maven { url "https://maven.google.com" }
    }
}

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

我正在使用Firebase Messaging Service,我想将通知发送到我的应用程序中。因此,我只是在检查日志中是否有任何更新。我的FirebaseMessagingService文件是:

public void onMessageReceived(RemoteMessage remoteMessage) {

        Log.d(TAG, "onMessageReceived: "+remoteMessage.getNotification().getTitle());

        Log.d(TAG, "onMessageReceived: "+remoteMessage.getNotification().getBody());

        Log.d(TAG, "onMessageReceived: "+remoteMessage.getData());

    }

在编译时,出现错误。如何解决?

3 个答案:

答案 0 :(得分:4)

根据Firebase official documentation,请将您的依赖项更新为最新版本。因此,请更改以下代码行:

compile 'com.google.firebase:firebase-core:16.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'

implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-messaging:17.3.0'

您还可以将项目的gradle升级到最新版本:

classpath 'com.android.tools.build:gradle:3.1.4'

答案 1 :(得分:1)

如果遇到此错误:

error: cannot access zza class file for com.google.android.gms.common.internal.safeparcel.zza not found

然后使用此:

implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.google.android.gms:play-services-location:11.8.0'

api 'com.google.firebase:firebase-messaging:17.0.0'

有效...

答案 2 :(得分:0)

添加此

    compile 'com.google.firebase:firebase-core:16.0.3'
    compile 'com.google.firebase:firebase-messaging:17.3.0'