You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When building an app with PublishTrimmed enabled, changing the device timezone crashes the app:
[monodroid] Unable to find Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()!
illinker seems to remove the method.
The timezone is often automatically changed by getting close to an other country, even though the time itself doesn't change. (changes to Europe/Amsterdam to Europe/Berlin)
The timezone can also be changed manually in the Android settings for the same effect.
Steps to Reproduce
Attached is a new Android 7 app with PublishTrimmed enabled in debug mode which shows the started timestamp in UI.
Start the app from Visual Studio in debug mode and note the time. Go to Android settings and change the current timezone to for example Afghanistan.
The app immediately crashes, VS stops debugging and the log shows the error message that AndroidEnvironment.NotifyTimeZoneChanged() is missing.
This happens in both emulator-33 and physical devices.
I would also like to add that this was very difficult to debug.
The message [monodroid] Unable to find Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()! only shows up in debug mode and not in release mode.
Nothing in adb logcat or adb bugreports.
Android's ActivityManager.GetHistoricalProcessExitReasons() only reports REASON_EXIT_SELF with signal 13. (it's not recognized as crash?)
If the app is immediately killed/aborted, I would at least expect the related error message to be present in logcat.
@rgroenewoudt The message is logged with the ANDROID_LOG_FATAL priority, can't get any higher alas. If it was missing from the logcat, then that's on Android I'm afraid.
Android's ActivityManager.GetHistoricalProcessExitReasons() only reports REASON_EXIT_SELF with signal 13. (it's not recognized as crash?)
Back in the day, calling exit() from the application would actually terminate the process. At some point Android changed the behavior and right now it mostly restarts the application if exit() is called. To quit the app, one needs to call abort() now. Until very recently, we weren't consistent in that, preserving a lot of older code that still called exit() on fatal failures.
@grendello do we need to do an audit of all mono_class_get_method_from_name calls and make sure we have xml to preserve it? Some might be fine to trim away, if we don't have to abort in those cases.
I will work on fixing this specific case -- adding a test. I think I can probably just try calling the method from System.Reflection in Release mode to assert that it exists.
@jonathanpeppers Isn't it a bug in the linker though? I was under impression that such lines preserve the entire type? If not, then what's the point of the <type> element?
@grendello do we need to do an audit of all mono_class_get_method_from_name calls and make sure we have xml to preserve it? Some might be fine to trim away, if we don't have to abort in those cases.
If the <type> element doesn't preserve the entire type, then yes, we probably need to list each method in the preserve lists.
No, the problem here is we removed <type fullname="Android.Runtime.AndroidEnvironment" />: 11f0e1b
We don't actually have anything preserving AndroidEnvironment.NotifyTimeZoneChanged(), if it isn't called from managed code the linker doesn't know about it.
Activity
rgroenewoudt commentedon Apr 12, 2023
I would also like to add that this was very difficult to debug.
The message
[monodroid] Unable to find Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()!only shows up in debug mode and not in release mode.Nothing in adb logcat or adb bugreports.
Android's
ActivityManager.GetHistoricalProcessExitReasons()only reports REASON_EXIT_SELF with signal 13. (it's not recognized as crash?)If the app is immediately killed/aborted, I would at least expect the related error message to be present in logcat.
grendello commentedon Apr 12, 2023
@rgroenewoudt The message is logged with the
ANDROID_LOG_FATALpriority, can't get any higher alas. If it was missing from the logcat, then that's on Android I'm afraid.grendello commentedon Apr 12, 2023
Back in the day, calling
exit()from the application would actually terminate the process. At some point Android changed the behavior and right now it mostly restarts the application ifexit()is called. To quit the app, one needs to callabort()now. Until very recently, we weren't consistent in that, preserving a lot of older code that still calledexit()on fatal failures.jonathanpeppers commentedon Apr 12, 2023
@grendello do we need to do an audit of all
mono_class_get_method_from_namecalls and make sure we have xml to preserve it? Some might be fine to trim away, if we don't have to abort in those cases.I will work on fixing this specific case -- adding a test. I think I can probably just try calling the method from System.Reflection in Release mode to assert that it exists.
[Microsoft.Android.Sdk.ILLink] fix crash when TZ changes
[Microsoft.Android.Sdk.ILLink] fix crash when TZ changes
grendello commentedon Apr 13, 2023
@jonathanpeppers Isn't it a bug in the linker though? I was under impression that such lines preserve the entire type? If not, then what's the point of the
<type>element?grendello commentedon Apr 13, 2023
If the
<type>element doesn't preserve the entire type, then yes, we probably need to list each method in the preserve lists.[Microsoft.Android.Sdk.ILLink] fix crash when TZ changes
jonathanpeppers commentedon Apr 13, 2023
No, the problem here is we removed
<type fullname="Android.Runtime.AndroidEnvironment" />: 11f0e1bWe don't actually have anything preserving
AndroidEnvironment.NotifyTimeZoneChanged(), if it isn't called from managed code the linker doesn't know about it.rgroenewoudt commentedon Apr 13, 2023
If only the .NET 5+ is supported, it might also be an idea to use DynamicallyAccessedMembersAttribute.
jonathanpeppers commentedon Apr 13, 2023
DynamicallyAccessedMembersAttributewould be good if using some type required this method, but I think all apps actually require it?[Microsoft.Android.Sdk.ILLink] fix crash when TZ changes (#7956)
[Microsoft.Android.Sdk.ILLink] fix crash when TZ changes (#7956)