【问题标题】:Firebase Messaging Error(Android only) - Fatal Exception on new Push NotificationFirebase 消息错误(仅限 Android) - 新推送通知的致命异常
【发布时间】:2019-03-13 06:38:58
【问题描述】:

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

我在 Flutter git 上找不到任何关于此的信息,因此可能是 android 问题。

当应用使用 Firebase 函数和 Firebase 消息传递收到新通知时,就会发生这种情况。我们使用的样本数据:

{
  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(Unknown Source: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
}

【问题讨论】:

  • 请添加build.gradle,因为单独的堆栈跟踪可能不够。

标签: android firebase flutter firebase-cloud-messaging


【解决方案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 语法可能(很可能)来自错误地发布 - 否则其他平台也无法运行;我刚刚添加了一个解释它有什么问题并删除了硬编码值。堆栈跟踪讲述了一个完全不同的故事,没有暗示任何无效语法。

【讨论】:

  • 很抱歉,我无法支持您的答案,但 firebase-messaging 的导入修复了它。实施 'com.google.firebase:firebase-messaging:17.3.3' 现在我不确定为什么在没有此导入的情况下它会在 6.0.0 中运行但谢谢
  • 你能解释一下为什么 firebase-pref 插件的顺序很重要,我没有遇到任何问题吗?
  • @ManuelBachmann 每个默认 Gradle 插件应该在 android 配置之前应用,以便它们可用(它是顺序执行) - 而 com.google.gms.google-services 是一个例外,它必须驻留在android 配置之后,因为它添加了源自解析的google-services.json 的值...基本上,首先引用插件,然后引用依赖于插件的库;它也可能在底部工作 - 虽然文档仍然建议将其放在顶部。
猜你喜欢
  • 2020-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-10
  • 2023-03-22
相关资源
最近更新 更多