Firebase Cloud Messaging引发的AbstractMethodError错误

8

我刚刚将我们的应用程序的GCM更改为FCM,并将OneSignal添加到其中。严格按照指南操作,甚至创建了一个新的监听器服务来处理推送通知。

然而,即使没有监听器,在我接收到推送时,应用程序也会崩溃,并显示以下消息:

09-27 14:11:21.483 25361-25361/com.appname.here E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.appname.here, PID: 25361
java.lang.AbstractMethodError: abstract method "android.content.Intent com.google.firebase.iid.zzb.zzae(android.content.Intent)"
    at com.google.firebase.iid.zzb.onStartCommand(Unknown Source)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3028)
    at android.app.ActivityThread.access$2200(ActivityThread.java:157)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1454)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5551)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

我已经从监听器中删除了所有代码,即使如此,仍然会出现这种情况。
我是实现方式有问题,还是遗漏了什么?
Build.gradle:
buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.22.0'
    }
}
apply plugin: 'com.android.application'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

apply plugin: 'io.fabric'
apply plugin: 'android-apt'

android {
    lintOptions {
        checkReleaseBuilds false
    }
    dexOptions {
        javaMaxHeapSize "2g"
    }
    signingConfigs {
        release {

        }
        debug {

        }
    }
    compileSdkVersion 24
    buildToolsVersion '24.0.1'

    defaultConfig {
        applicationId "com.appname.here"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode getDate()
        versionName '2.1.0'
        multiDexEnabled true

        manifestPlaceholders = [manifestApplicationId: "${applicationId}",
                                onesignal_app_id: "*******",
                                onesignal_google_project_number: "********"]
    }

    applicationVariants.all { variant ->
        def apkName = "appnamehere";
        apkName += "_" + variant.buildType.name + "_" + android.defaultConfig.versionName + "_" + android.defaultConfig.versionCode;
        variant.outputs.each { output ->
            output.outputFile = new File(output.outputFile.parent, apkName + ".apk");
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            debuggable true
            jniDebuggable true
            signingConfig signingConfigs.release
            renderscriptDebuggable true

        }
    }
    productFlavors {
        Live {
            signingConfig signingConfigs.release
        }
        Develop {
            signingConfig signingConfigs.release
            applicationIdSuffix ".develop"
        }
    }
}

def getDate() {
    def date = new Date()
    def formattedDate = date.format('yyMMddHHmm')
    return formattedDate.toInteger()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    //compile project(':libphonenumber-5.9')
    compile project(':jaalee-sdk')
    compile project(':socialauth-android-3.2')
    compile('com.crashlytics.sdk.android:crashlytics:2.6.4@aar') {
        transitive = true;
    }

    compile 'com.google.android.gms:play-services-gcm:9.6.1'
    compile 'com.onesignal:OneSignal:3.3.0@aar'

    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.android.support:customtabs:24.2.1'
//    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha5'
    compile 'com.google.android.gms:play-services-ads:9.6.1'
    compile 'com.google.android.gms:play-services-analytics:9.6.1'
    compile 'com.google.android.gms:play-services-auth:9.6.1'
    compile 'com.google.android.gms:play-services-identity:9.6.1'
    compile 'com.google.android.gms:play-services-location:9.6.1'
    compile 'com.google.android.gms:play-services-maps:9.6.1'
    compile 'com.google.maps.android:android-maps-utils:0.4'
    compile 'com.googlecode.libphonenumber:libphonenumber:7.5.2'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.jakewharton:butterknife:8.2.1'
    compile 'com.thebluealliance:spectrum:0.5.0'
    compile 'com.joanzapata.iconify:android-iconify-entypo:2.2.2'
    compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2'
    compile 'com.joanzapata.iconify:android-iconify-material:2.2.2'
    compile 'com.joanzapata.iconify:android-iconify-material-community:2.2.2'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.jonathanfinerty.once:once:1.2.1'
    apt 'com.jakewharton:butterknife-compiler:8.2.1'

    compile 'com.google.firebase:firebase-core:9.2.0'
    compile "com.google.firebase:firebase-messaging:9.0.2"

    compile 'com.github.clans:fab:1.6.4'                // Expandable floating button.
    compile 'com.androidadvance:topsnackbar:1.1.1'      // Top snackbar.
    compile 'com.baoyz.swipemenulistview:library:1.3.0' // Swipeable listview.
    compile 'me.relex:circleindicator:1.2.1@aar'        // Pager indicator.
    compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
}

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

crashlytics {
    enableNdk true
    androidNdkOut 'src/main/obj'
    androidNdkLibsOut 'src/main/libs'
}

请发布详细的logcat和您的build.gradle。 - Rushi M Thakker
logcat 就只有这个条目,没有其他的。我马上会发布应用程序模块的 build.gradle,但需要先删除一些专有和受 NDA 保护的内容。 - fonix232
@FrankVanPuffelen,请为此添加到文档中提供动力。 - Richard Le Mesurier
2个回答

30

将Firebase库的版本号更新为与其他Google Play服务库一致:

修改为:

compile 'com.google.firebase:firebase-core:9.2.0'
compile "com.google.firebase:firebase-messaging:9.0.2"

收件人:

compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'

谢谢!我现在正在尝试。有趣的是,Android Studio通常会在需要更新软件包或版本绑定时进行通知。 - fonix232
好的,确实是这个问题。感谢您的帮助! - fonix232
1
绝对的 - 这个应该写在文档里。 - Richard Le Mesurier

0

当你在wat中定义你的待定意图时,就会发生这种情况。

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

所以在上面我添加了'this',但应该有一个上下文或源活动。

它应该像解决方案1这样。

        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

解决方案2

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

在上面的代码中,你需要传递上下文,可以通过参数或者适合你的任何方法来实现。


请查看已接受的答案。主要问题是Play Services和Firebase库不在同一个版本上。 - fonix232

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接