Open tranb3r opened 1 year ago
When trimming my application, android's MyFirebaseMessagingService
is removed.
I can workaround that issue by disabling trimming for Plugin.Firebase.CloudMessaging
.
But maybe this could be fixed in the plugin's code, by ensuring the service is always preserved?
Okay yes, I will add the Preserve
attribute to the MyFirebaseMessagingService
and release it with the next Plugin.Firebase.CloudMessaging
version 👍
Ok but I'm not 100% sure that the Preserve
attribute is still the way to preserve code in dotnet maui.
Can you confirm that?
No, I can't confirm that, I was just assuming it would work. What would be the alternative?
I've asked for help on discord, here is what I've understood.
The Preserve
attribute is now obsolete, and the linker is ignoring it.
You should instead use the DynamicDependency
as explained here.
The best place to add this attribute would be the entry point of the library.
So I think the proper way to fix the missing MyFirebaseMessagingService
would be to add an Initialize
method to CrossFirebaseCloudMessaging
and decorate it with the DynamicDependency
attribute.
Disabling trimming completely until this is resolved. The workarounds no longer work for me.
Until this one ships:
I found putting this in your app seems to workaround the issue:
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(MyFirebaseMessagingService))]
Can anyone confirm if it solve the problem for them?
Is this only happening when using TrimMode=full
, or does it also occur with default settings?
@jonathanpeppers Seems like it's working just fine with DynamicDependency attribute ! Even if Preserve attribute is flagged as Obsolete, still being usable is a bit confusing since it seems to have stopped working properly
No, I don't think we can remove [ObsoleteAttribute]
as that would be a breaking change. Random Xamarin.Android class libraries (such as old NuGets) could throw TypeLoadException
(or possibly even more inscrutable runtime errors).
It does seem like we could add [Obsolete(error: true)]
in .NET 9, so you'd get a build error in new source code if you used [PreserveAttribute]
. I'll think on it.
Hi,
When migrating playground/tests to dotnet maui, the
<AndroidLinkMode>Full</AndroidLinkMode>
property has been removed from the release build. I don't know if it's been done on purpose, but I think you could add now the corresponding dotnet trimmer property:<TrimMode>full</TrimMode>
.Also, are you sure the
Preserve
attributes in the plugin code are still needed? Maybe it's worth testing it again with dotnet trimmer. What do you think?Thanks!