-
Notifications
You must be signed in to change notification settings - Fork 308
Notifications missing in release build on Android #528
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
Comments
Hmm! When I reproduce the issue while the app is in the foreground, if I then go to the notification history (system settings > Notifications > Notification history), the notification does appear there! It's under the heading "Recently dismissed". Still a mystery why the actual visible notification never shows up. But that does mean that our request to show a notification is reaching the relevant Android API. And adding debug logging confirms that the whole chain is getting successfully executed:
In light of that, I can also now observe that
and the information about the notification never reaches Dart, and no notification appears in the system notification history. When I add that pragma, those errors don't appear, and the behavior when in the background is just like the behavior in the foreground. So the pragma demonstrably helps, when in the background… but there's some independent issue, later in the pipeline, which is causing the notifications to not actually show up in the normal UI for notifications. That one is still in need of debugging. |
This fixes part of zulip#528, following the suggestion n-92 made here: zulip#342 (comment) Even with this change, notifications still don't yet work on Android in release builds. But after this change, when the app wasn't in the foreground, they get farther than before. Specifically they get just as far as they get, with or without this change, when the app was in the foreground. Details here: zulip#528 (comment)
Aha! Searching the There are a number of threads where people report similar symptoms: the notifications work in debug mode, but not in release mode. In several of those threads, the maintainer links to a README section about configuring resource shrinking so that it doesn't discard the notification icon — when the system can't find the specified icon, it rejects the notification. We don't say anything about resource shrinking or minification or Proguard or anything like that in our own if (shouldShrinkResources(project)) {
release {
// Enables code shrinking, obfuscation, and optimization for only
// your project's release build type.
minifyEnabled(true)
// Enables resource shrinking, which is performed by the Android Gradle plugin.
// The resource shrinker can't be used for libraries.
shrinkResources(isBuiltAsApp(project))
// Fallback to `android/app/proguard-rules.pro`.
// This way, custom Proguard rules can be configured as needed.
proguardFiles(project.android.getDefaultProguardFile("proguard-android.txt"), flutterProguardRules, "proguard-rules.pro")
}
} That private static Boolean shouldShrinkResources(Project project) {
final String propShrink = "shrink"
if (project.hasProperty(propShrink)) {
return project.property(propShrink).toBoolean()
}
return true
} So we can tell Flutter not to enable shrinking by specifying
And when I do that, notifications work! So that confirms the diagnosis: the reason notifications aren't working in release builds is because of this resource shrinking. It turns out there's also an entry in the Android logs that reports the error. The reason I hadn't seen it before is that it doesn't get reported on the app's own package, but instead on a system package. Here it is (or rather a pair of entries), about 250ms after the call to
So, we have a diagnosis. I think it's now the end of the day for me, but I'll pick this up later to make a fix. (It won't involve |
(Context here is that the Android logs, aka what |
This fixes part of #528, following the suggestion n-92 made here: #342 (comment) Even with this change, notifications still don't yet work on Android in release builds. But after this change, when the app wasn't in the foreground, they get farther than before. Specifically they get just as far as they get, with or without this change, when the app was in the foreground. Details here: #528 (comment)
Interesting—thanks for doing all this investigation! Looking forward to a fix, and I've just merged #529. |
…away Details in the new comment and in the issue thread. Fixes: zulip#528
…away Details in the new comment and in the issue thread. Fixes: #528
After the PR #521 which fixed #520, I can no longer reproduce any trouble receiving notifications on Android, regardless of whether the app is already running in the foreground, in the background, or not at all… so long as I'm using a debug build of the app.
But when I run a release build of the app instead — which of course is what we distribute to users — I don't get any notifications at all. Not when the app is in the foreground, not when it's in the background, and not when it's not running.
I'm investigating this now. A quick first observation is that it's unaffected by the
@pragma('vm:entry-point')
change suggested at #342 (comment) ; it reproduces the same way after I add the pragma.The text was updated successfully, but these errors were encountered: