Flutter - 在构建 APK 时看不到通知图标
Flutter - cannot see the notification icon on build APK
我在我的项目中使用 flutter_local_notifications 4.0.1+2,当 运行 在模拟器中调试 apk 时通知图标可见,但构建 apk 时显示彩色方块而不是图标。谁能帮我解决这个问题?
可能是您没有在正确的位置指定通知图标。它应该在 android/app/src/main/res/drawable
文件夹中,例如android/app/src/main/res/drawable/notification_icon.xml
。然后,您可以添加
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon" />
在 android/app/src/main/AndroidManifest.xml
中。可能是您在 android/app/src/debug/
中指定了您的图标,这在构建您的发布 apk 时没有被考虑在内。
编辑
notification_icon.xml
的例子:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="221.9dp"
android:height="208.1dp"
android:viewportWidth="221.9"
android:viewportHeight="208.1">
<path
android:pathData="M152.4,0h-83L0,208.1h221.9L152.4,0zM110.9,56.4l18.6,57.7l60.6,-0.1l-49.1,35.5l18.8,57.6l-49,-35.7l-49,35.7l18.8,-57.6L31.7,114l60.6,0.1L110.9,56.4z"
android:fillColor="#006600"
android:fillType="evenOdd" />
</vector>
为了显示您的自定义应用程序图标,您需要在 Android 清单文件的标签中设置图标。参考以下link,希望对您有所帮助
我在我的项目中使用 flutter_local_notifications 4.0.1+2,当 运行 在模拟器中调试 apk 时通知图标可见,但构建 apk 时显示彩色方块而不是图标。谁能帮我解决这个问题?
可能是您没有在正确的位置指定通知图标。它应该在 android/app/src/main/res/drawable
文件夹中,例如android/app/src/main/res/drawable/notification_icon.xml
。然后,您可以添加
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon" />
在 android/app/src/main/AndroidManifest.xml
中。可能是您在 android/app/src/debug/
中指定了您的图标,这在构建您的发布 apk 时没有被考虑在内。
编辑
notification_icon.xml
的例子:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="221.9dp"
android:height="208.1dp"
android:viewportWidth="221.9"
android:viewportHeight="208.1">
<path
android:pathData="M152.4,0h-83L0,208.1h221.9L152.4,0zM110.9,56.4l18.6,57.7l60.6,-0.1l-49.1,35.5l18.8,57.6l-49,-35.7l-49,35.7l18.8,-57.6L31.7,114l60.6,0.1L110.9,56.4z"
android:fillColor="#006600"
android:fillType="evenOdd" />
</vector>
为了显示您的自定义应用程序图标,您需要在 Android 清单文件的标签中设置图标。参考以下link,希望对您有所帮助