Skip to content

notif android: Keep the notification icon from being resource-shrunk away #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions android/app/src/main/res/raw/keep.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is necessary for notifications to work in release builds.

The issue is that the package:flutter_local_notifications API has us
identify which icon we want to use via a string name, in Dart code,
and that's invisible to the resource shrinker:
https://developer.android.com/build/shrink-code#keep-resources
If the icon isn't named in this file, it gets removed in release builds
(more precisely, replaced with a 0-byte file, which is invalid for its
image format). The system then discards notifications that try to use
the invalid icon file:
https://github.com/zulip/zulip-flutter/issues/528
-->
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@drawable/zulip_notification"
/>
3 changes: 2 additions & 1 deletion lib/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ class NotificationDisplayManager {
'(Zulip internal error)', // TODO never implicitly create channel: https://github.com/MaikuB/flutter_local_notifications/issues/2135
tag: conversationKey,
color: kZulipBrandColor,
icon: 'zulip_notification', // TODO vary for debug
// TODO vary notification icon for debug
icon: 'zulip_notification', // This name must appear in keep.xml too: https://github.com/zulip/zulip-flutter/issues/528
// TODO(#128) inbox-style

// TODO plugin sets PendingIntent.FLAG_UPDATE_CURRENT; is that OK?
Expand Down