Error: adaptive icons with no fallback drawable for FCM notifications, can cause irreversible crash on Android Oreo

Error: adaptive icons with no fallback drawable for FCM notifications, can cause irreversible crash on Android Oreo

今天开发 Android 应用程序时,我在 logcat 中收到以下错误消息:

You are targeting Android Oreo and using adaptive icons without having a fallback drawable set for FCM notifications. This can cause a irreversible crash on devices using Oreo. To learn more about this issue check: https://issuetracker.google.com/issues/68716460

我花了一段时间才弄清楚意思和做什么,所以我在下面添加一个答案。

这是 Pusher Beams Android SDK warning about a bug in Android 8.0 Oreo. See this article for more information about it. Also, check out 生成的错误。

如上述链接和 here in the documentation 中所述,要解决该问题,请将以下 meta-data 添加到您的 AndroidManifest:

<manifest ...>
    <application...>

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_default_notification" />
       <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/colorAccent" />

    </application>
</manifest>

其中 ic_default_notification 是您自己创建的内容。要在 Android Studio 中制作,请右键单击 drawable 文件夹并选择 New > Image Asset。对于图标类型,选择通知图标