gpt4 book ai didi

android - Firebase 消息传递错误(仅限 Android)- 新推送通知的致命异常

转载 作者:IT王子 更新时间:2023-10-29 06:43:55 26 4
gpt4 key购买 nike

我们目前正在使用 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): FATAL EXCEPTION: Firebase-FlutterFirebaseMessagingService E/AndroidRuntime( 3436): Process: de.mandarinmedien.jutta, PID: 3436 E/AndroidRuntime( 3436): java.lang.NoSuchMethodError: No static method zzc(Landroid/content/Context;)Lcom/google/firebase/iid/zzz; in class Lcom/google/firebase/iid/zzz; or its super classes (declaration of 'com.google.firebase.iid.zzz' appears in /data/app/de.mandarinmedien.jutta-gn2RX8mWXXycpVEEEZIaNQ==/base.apk:classes3.dex) E/AndroidRuntime( 3436): at com.google.firebase.messaging.FirebaseMessagingService.zzd(Unknown Source:110) E/AndroidRuntime( 3436): at com.google.firebase.iid.zzg.run(Unknown Source:4) E/AndroidRuntime( 3436): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) E/AndroidRuntime( 3436): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) E/AndroidRuntime( 3436): at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:6) E/AndroidRuntime( 3436): at 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
}

最佳答案

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,还建议设置一个通知 channel :

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

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

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

关于android - Firebase 消息传递错误(仅限 Android)- 新推送通知的致命异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52704849/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com