Firebase消息错误(仅适用于Android)-新的推送通知发生致命异常

时间:2018-10-08 14:49:39

标签: android firebase flutter firebase-cloud-messaging

我们当前正在使用flutter开发一款可接收推送通知的应用。一切正常,直到我们进行了最后一次Flutter更新,现在我们仅在Android上的Firebase中获得了致命异常-FlutterFirebaseMessagingService。

我在Flutter git上找不到关于此的任何信息,所以这可能是一个Android问题。

当应用程序使用Firebase功能和Firebase Messaging获得新的通知时,就会发生这种情况。我们使用的示例数据:

{
  notification: {
        title: „hello",
        body: „You got a new Message"
    },
    data: {
        click_action: "FLUTTER_NOTIFICATION_CLICK",
        additional: additional, // some integer values
        message: messageText // Same as message body above
    },
    apns: {
        payload: {
            aps: {
                badge: count,
            },
        },
    },
    token: deviceToken //this is a correct device id
}


admin.messaging().send(message)

完整设备日志

  

E / AndroidRuntime(3436):致命异常:   Firebase-FlutterFirebaseMessagingService E / AndroidRuntime(3436):   流程:de.mandarinmedien.jutta,PID:3436 E / AndroidRuntime(3436):   java.lang.NoSuchMethodError:没有静态方法   zzc(Landroid / content / Context;)Lcom / google / firebase / iid / zzz;在班上   Lcom / google / firebase / iid / zzz;或其超类(声明为   “ com.google.firebase.iid.zzz”出现在   /data/app/de.mandarinmedien.jutta-gn2RX8mWXXycpVEEEZIaNQ==/base.apk:classes3.dex)   E / AndroidRuntime(3436):在   com.google.firebase.messaging.FirebaseMessagingService.zzd(未知   来源:110)E / AndroidRuntime(3436):位于   com.google.firebase.iid.zzg.run(未知来源:4)E / AndroidRuntime(   3436):   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)   E / AndroidRuntime(3436):在   java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:636)   E / AndroidRuntime(3436):在   com.google.android.gms.common.util.concurrent.zza.run(未知   来源:6)E / AndroidRuntime(3436):位于   java.lang.Thread.run(Thread.java:764)

是否有人已经对此错误有经验或有解决该错误的想法?

编辑:android / app / build.gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId ******
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "0.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.debug
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.google.firebase:firebase-perf:16.0.0'
}

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

android / build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.2.1'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex')) {
                details.useVersion "27.1.1"
            }
        }
    }

}

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

1 个答案:

答案 0 :(得分:1)

错误消息提示iid;实例ID服务。这可能由firebase-core提供;同时它也可能是不兼容的版本,有时会导致方法和字段未知。

尝试更新:

classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.2.1'

到当前版本:

classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.google.gms:google-services:4.1.0'

firebase-perf插件必须位于顶部,而不是底部:

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'

该库也已过时(可能需要firebase-core):

implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-perf:16.1.2'

我真的很奇怪,为什么FCM没有依赖性(就像人们期望的那样):

implementation 'com.google.firebase:firebase-messaging:17.3.3'

一旦定位到API级别28,建议您设置一个通知渠道:

<meta-data
    android:name="com.google.firebase.messaging.default_notification_channel_id"
    android:value="@string/default_notification_channel_id" />

...当前支持库的版本为28.0.0

备注:无效的JSON语法可能(最有可能)来自错误地发布-否则其他平台也将无法运行;我刚刚添加了一个解释,它有什么问题,并删除了硬编码的值。堆栈跟踪讲述了一个完整的故事,没有暗示任何无效的语法。