-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changing timezone crashes app #7953
Comments
I would also like to add that this was very difficult to debug. Android's 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 |
Back in the day, calling |
@grendello do we need to do an audit of all 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. |
Fixes: dotnet#7953 **WIP** seeing what the test does on CI. When a timezone changes in a `Release` app, it can crash with: [monodroid] Unable to find Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()! In 11f0e1b, we removed the line: <?xml version="1.0" encoding="utf-8" ?> <linker> <assembly fullname="Mono.Android"> -- <type fullname="Android.Runtime.AndroidEnvironment" /> Unfortunately, this method is called from native code, so we need to *always* preserve it. Added a test for this scenario, we may want to audit all `mono_class_get_method_from_name` calls and add more tests cases. I also cleaned up the tests a bit with a `getResource()` local function.
Fixes: dotnet#7953 When a timezone changes in a `Release` app, it can crash with: [monodroid] Unable to find Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()! In 11f0e1b, we removed the line: <?xml version="1.0" encoding="utf-8" ?> <linker> <assembly fullname="Mono.Android"> -- <type fullname="Android.Runtime.AndroidEnvironment" /> Unfortunately, this method is called from native code, so we need to *always* preserve it. Added a test for this scenario, we may want to audit all `mono_class_get_method_from_name` calls and add more tests cases. I also cleaned up the tests a bit with a `getResource()` local function.
@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 |
If the |
Fixes: dotnet#7953 When a timezone changes in a `Release` app, it can crash with: [monodroid] Unable to find Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()! In 11f0e1b, we removed the line: <?xml version="1.0" encoding="utf-8" ?> <linker> <assembly fullname="Mono.Android"> -- <type fullname="Android.Runtime.AndroidEnvironment" /> Unfortunately, this method is called from native code, so we need to *always* preserve it. Added a test for this scenario, we may want to audit all `mono_class_get_method_from_name` calls and add more tests cases. I also cleaned up the tests a bit with a `getResource()` local function.
No, the problem here is we removed We don't actually have anything preserving |
If only the .NET 5+ is supported, it might also be an idea to use DynamicallyAccessedMembersAttribute. |
|
Fixes: #7953 Context: 11f0e1b When a timezone changes in a `Release` config app, it can crash with: [monodroid] Unable to find Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()! In commit 11f0e1b, we removed the line: <?xml version="1.0" encoding="utf-8" ?> <linker> <assembly fullname="Mono.Android"> -- <type fullname="Android.Runtime.AndroidEnvironment" /> Unfortunately, `AndroidEnvironment.NotifyTimeZoneChanged()` is called from non-managed code, via: * The `NotifyTimeZoneChanges` broadcast receiver (in `src/java-runtime/java/mono/android/app/NotifyTimeZoneChanges.java`) which calls- * The `Rutime.notifyTimeZoneChanged()` `native` method (in `src/java-runtime/java/mono/android/Runtime.java`), implemented in- * `Java_mono_android_Runtime_notifyTimeZoneChanged()` (in`src/monodroid/jni/timezones.cc`). The managed linker cannot "see" any of these references, so we need to *always* preserve this method, as it is always callable. Update `src/Microsoft.Android.Sdk.ILLink/PreserveLists/Mono.Android.xml` so that `Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()` is always preserved. Added a test for this scenario. TODO: we may want to audit all `mono_class_get_method_from_name()` calls and add more tests cases. I also cleaned up the tests a bit with a `getResource()` local function.
Fixes: #7953 Context: 11f0e1b When a timezone changes in a `Release` config app, it can crash with: [monodroid] Unable to find Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()! In commit 11f0e1b, we removed the line: <?xml version="1.0" encoding="utf-8" ?> <linker> <assembly fullname="Mono.Android"> -- <type fullname="Android.Runtime.AndroidEnvironment" /> Unfortunately, `AndroidEnvironment.NotifyTimeZoneChanged()` is called from non-managed code, via: * The `NotifyTimeZoneChanges` broadcast receiver (in `src/java-runtime/java/mono/android/app/NotifyTimeZoneChanges.java`) which calls- * The `Rutime.notifyTimeZoneChanged()` `native` method (in `src/java-runtime/java/mono/android/Runtime.java`), implemented in- * `Java_mono_android_Runtime_notifyTimeZoneChanged()` (in`src/monodroid/jni/timezones.cc`). The managed linker cannot "see" any of these references, so we need to *always* preserve this method, as it is always callable. Update `src/Microsoft.Android.Sdk.ILLink/PreserveLists/Mono.Android.xml` so that `Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()` is always preserved. Added a test for this scenario. TODO: we may want to audit all `mono_class_get_method_from_name()` calls and add more tests cases. I also cleaned up the tests a bit with a `getResource()` local function.
Android application type
.NET Android (net7.0-android, etc.)
Affected platform version
VS2022 17.5.4, .NET 7 Android
Description
When building an app with PublishTrimmed enabled, changing the device timezone crashes the app:
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.
AndroidApp1.zip
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.
Did you find any workaround?
Add a linker description file containing:
To prevent the method being trimmed away.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: