-
Notifications
You must be signed in to change notification settings - Fork 529
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
TrimMode=full
seems to break android push notifications on MAUI .net 9 preview 3
#8940
Comments
Also, there is plenty of evidence people seem to be accepting "turning off trimming" as a "solution". But that's not how it should be right? At the very least it's not clear to the average user (like me) what needs to be done in this case :) please help me solve the issue that has been wrecking my brain for months. |
@jkommeren can you share a sample app that shows this issue? If some code in your app is supposed to be running (and isn't), is the code trimmed away? We could inspect a Release Generally, you can preserve a single method as a workaround instead of disabling trimming completely. But you, of course, would need to know which method. |
Thank you for your swift reply. How can I inspect the APK? 😊 |
If you run this tool on an Then you can just open them in ILSpy or your favorite decompiler. |
The problem here is that the trimmer is getting rid of an android service in the |
Also, about inspecting the apk, I've found that the easiest way to do it is to look into |
@jkommeren so are you using Services should not be trimmed away by default -- it should be using |
Yes this is with full trimming. |
@jonathanpeppers yes indeed with full trimming. I think I'm making progress. With the suggestions from tranb3r I have managed to get it working with .net 8 and his library Plugin.Firebase. But then I removed his suggestions, and it was still working (but I'm guessing that's because I didn't do a full clean of obj and bin folders, just from VS) I'm still a bit puzzled why my own implementation of the FirebaseMessagingService (SuperFirebaseMessagingService.OnMessageReceived) is not being fired though, even though it's present in the DLL (looking at DnSpy), in the linked folder like suggested, and it's working in Debug mode. I think there's something I'm missing. I can create a sample project this weekend to upload and have a proper go at .net 9 preview 3. Trimming is definitely different there, it's much slower too :D Thanks for your help so far. |
I wouldn't expect But it still seems like there might be some things that we should go test in .NET 9 w/
I wonder if some of these are trimmed away and shouldn't be. |
TrimMode=full
seems to break android push notifications on MAUI .net 9 preview 3
…ttribute` Fixes: dotnet#8940 Context: TobiasBuchholz/Plugin.Firebase#144 Using the NuGet package: <PackageReference Include="Plugin.Firebase.CloudMessaging" Version="3.0.0" /> Includes a service: namespace Plugin.Firebase.CloudMessaging.Platforms.Android; [Service(Exported = true)] [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })] public class MyFirebaseMessagingService : FirebaseMessagingService Unfortunately, using `TrimMode=full` completely trims away the above service, which is required for push notifications to work. I could reproduce this problem in a test using the above NuGet package. To fix this, we can modify `MarkJavaObjects` to preserve types with attributes that implement `Java.Interop.IJniNameProviderAttribute`, and the new test now passes.
Android application type
.NET Android (net7.0-android, net8.0-android, etc.)
Affected platform version
VS 2022 17.10.0 preview 7
Description
Notifications don't arrive in some cases when "PublishTrimmed" is set to true and building it in Release mode (which is the default)
Point is: @jonathanpeppers suggested to create a new issue here if the issue still persisted on .net 9 preview 3. As far as I'm aware it has been an issue at least since .net 7, but also very likely .net 6.
Originally posted by @jonathanpeppers in #5652 (comment)
Also mentioned in dotnet/maui#16014
And at least some people seem to be affected here dotnet/maui#19900
Steps to Reproduce
Did you find any workaround?
Set PublishTrimmed to False or deploying in debug mode fixes the issue immediately: Then the notification does arrive.
Also one odd thing: When the application is in the background, sending a notification via the Firebase console does pop up.
(But if it's sent as a Data message instead, the FirebaseMessagingService does not pick it up in foreground nor background. That is also fixed by using non-trimming or debug)
Maybe there's something I completely don't understand about Android notifications in MAUI, but the way I understand it, Debug should behave like Release mode in these cases right? And Non-trimmed vs Trimmed in Release mode too?
Relevant log output
The text was updated successfully, but these errors were encountered: