致命异常:android.app.RemoteServiceException .... 无法创建图标:StatusBarIcon

Oma*_*din 8 android android-notifications

我的实时用户在 Crashlytics 上发布了数百次此异常,但我无法在 5 个不同的设备上重现它一次

崩溃日志

致命异常:android.app.RemoteServiceException:从包 com.mypackage 发布的错误通知:无法创建图标:StatusBarIcon(icon=Icon(typ=RESOURCE pkg=com.mypackage id=0x7f08009e) visible user=0 ) at android。 app.ActivityThread$H.handleMessage(ActivityThread.java:2046) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread .main(ActivityThread.java:7406) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android。 internal.os.ZygoteInit.main(ZygoteInit.java:1120)

我发布通知的唯一地方是来自FirebaseMessagingService 这里是发布通知的代码

private fun sendNotification(remoteMessage: RemoteMessage) {
    val intent = Intent(this, MainActivity::class.java)
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
    val pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT)
    val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
    val notificationBuilder = NotificationCompat.Builder(this, "")
            .setContentText(remoteMessage.notification?.body)
            .setContentTitle(remoteMessage.notification?.title)
            .setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_notification)
            .setSound(defaultSoundUri)
            .setColor(ContextCompat.getColor(this, R.color.blue_accent_color))
            .setContentIntent(pendingIntent)
    val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build())
}
Run Code Online (Sandbox Code Playgroud)

需要提及的事情: 1- drawable 不是矢量可绘制的,它是在 (mdpi, hdpi, xhdpi. xxhdpi, xxxhdpi) 中找到的具有透明背景的 png
2- drawable 是由Android Assets Studio创建的
3- 这可能是重复的对于这个问题,我不太确定那里是否有解决方案

如何解决这个问题,或者有一个解决方法来防止它发生,我什至不知道如何重现它以便我可以尝试解决这个问题

Max*_*Max 1

在将项目迁移到较早的 SDK 版本(版本 23)后,我遇到了这个问题。我发现该项目有两个版本的 tne .xml 文件,其中包含小图标资源(在我的例子中为 res/drawable/ic_launcher_foreground.xml 和 res/drawable -v24/ic_launcher_foreground.xml)。当我删除与 v24 关联的 .xml 时,崩溃停止了。