dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.92k stars 526 forks source link

[android] MAUI app with localized resources build on Windows crashes with non-default culture #9151

Open matouskozak opened 1 month ago

matouskozak commented 1 month ago

Description

Android MAUI app with localized resources crashes in Release configuration on startup with non-default culture. The app crashes when built on Windows, when built on Mac the app works fine. This failure was originally reported in https://github.com/dotnet/android/issues/9153.

When the app is built in Debug configuration, the app doesn't crash. However, the non-default culture is not respected and localized resources for default culture are used.

Reproduction Steps

  1. Install .NET 9 preview 5 and MAUI-android workload
  2. Create a MAUI app using localized resources
  3. Change culture: either in the MauiProgram.cs e.g. with System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("cs-CZ"); or by going into device settings and changing language/location manually.
  4. Build and run the app for android (-f net9.0-android) in Release mode (-c Release)

Expected behavior

The app builds and runs without errors, displaying the localized resources for the changed culture.

Actual behavior

The app crashes on startup with:

07-25 15:06:31.941 14348 14348 D Mono    : Request to load AndroidGlobalizationRepro.resources in alc 0x7c9d68e9ba70
07-25 15:06:31.941 14348 14348 D monodroid-assembly: assembly_store_open_from_bundles: looking for bundled name: 'cs-CZ/AndroidGlobalizationRepro.resources' (hash 0xf878a992386a932a)
07-25 15:06:31.941 14348 14348 D monodroid-assembly: Mapped: image_data == 0x7c9c1850464c; debug_info_data == 0x0; config_data == 0x0; descriptor == 0x7c9c18286348; data size == 3584; debug data size == 0; config data size == 0; name == 'cs-CZ/AndroidGlobalizationRepro.resources'
07-25 15:06:31.942 14348 14348 F monodroid-assembly: Failed to look up image index for hash 0xf878a992386a932a
07-25 15:06:31.942 14348 14348 F monodroid: Abort at /Users/runner/work/1/s/xamarin-android/src/native/monodroid/mono-image-loader.hh:120:5 ('static MonoImage *xamarin::android::internal::MonoImageLoader::stash_and_return(MonoImage *, MonoImageOpenStatus, hash_t)')
--------- beginning of crash
07-25 15:06:31.944 14348 14348 F libc    : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 14348 (balizationrepro), pid 14348 (balizationrepro)
07-25 15:06:32.001 14391 14391 E crash_dump64: failed to get the guest state header for thread 14348: Bad address
07-25 15:06:32.004 14391 14391 E crash_dump64: failed to get the guest state header for thread 14349: Bad address
07-25 15:06:32.004 14391 14391 E crash_dump64: failed to get the guest state header for thread 14350: Bad address
07-25 15:06:32.005 14391 14391 E crash_dump64: failed to get the guest state header for thread 14351: Bad address
07-25 15:06:32.006 14391 14391 E crash_dump64: failed to get the guest state header for thread 14352: Bad address
07-25 15:06:32.007 14391 14391 E crash_dump64: failed to get the guest state header for thread 14353: Bad address
07-25 15:06:32.008 14391 14391 E crash_dump64: failed to get the guest state header for thread 14354: Bad address
07-25 15:06:32.009 14391 14391 E crash_dump64: failed to get the guest state header for thread 14355: Bad address
07-25 15:06:32.011 14391 14391 E crash_dump64: failed to get the guest state header for thread 14357: Bad address
07-25 15:06:32.014 14391 14391 E crash_dump64: failed to get the guest state header for thread 14358: Bad address
07-25 15:06:32.014 14391 14391 E crash_dump64: failed to get the guest state header for thread 14359: Bad address
07-25 15:06:32.016 14391 14391 E crash_dump64: failed to get the guest state header for thread 14360: Bad address
07-25 15:06:32.016 14391 14391 E crash_dump64: failed to get the guest state header for thread 14365: Bad address
07-25 15:06:32.017 14391 14391 E crash_dump64: failed to get the guest state header for thread 14379: Bad address
07-25 15:06:32.018 14391 14391 E crash_dump64: failed to get the guest state header for thread 14380: Bad address
07-25 15:06:32.019 14391 14391 E crash_dump64: failed to get the guest state header for thread 14386: Bad address
07-25 15:06:32.035 14391 14391 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstoneProto
07-25 15:06:32.037   220   220 I tombstoned: received crash request for pid 14348
07-25 15:06:32.043 14391 14391 I crash_dump64: performing dump of process 14348 (target tid = 14348)
07-25 15:06:33.330 14391 14391 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-25 15:06:33.330 14391 14391 F DEBUG   : Build fingerprint: 'google/sdk_gphone64_x86_64/emu64xa:15/AP31.240617.003/12088229:user/release-keys'
07-25 15:06:33.330 14391 14391 F DEBUG   : Revision: '0'
07-25 15:06:33.330 14391 14391 F DEBUG   : ABI: 'x86_64'
07-25 15:06:33.331 14391 14391 F DEBUG   : Timestamp: 2024-07-25 15:06:32.055607800+0200
07-25 15:06:33.331 14391 14391 F DEBUG   : Process uptime: 7s
07-25 15:06:33.331 14391 14391 F DEBUG   : Cmdline: com.companyname.androidglobalizationrepro
07-25 15:06:33.331 14391 14391 F DEBUG   : pid: 14348, tid: 14348, name: balizationrepro  >>> com.companyname.androidglobalizationrepro <<<
07-25 15:06:33.331 14391 14391 F DEBUG   : uid: 10212
07-25 15:06:33.331 14391 14391 F DEBUG   : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
07-25 15:06:33.331 14391 14391 F DEBUG   : Abort message: 'Failed to look up image index for hash 0xf878a992386a932a'
07-25 15:06:33.331 14391 14391 F DEBUG   :     rax 0000000000000000  rbx 00007ffee8f616b8  rcx 00007c9f438e0b90  rdx 0000000000000006
07-25 15:06:33.331 14391 14391 F DEBUG   :     r8  00007c9c9fa5cb31  r9  00007c9c9fa5cb31  r10 00007ffee8f616c0  r11 0000000000000203
07-25 15:06:33.331 14391 14391 F DEBUG   :     r12 00007c9c1850464c  r13 00007ffee8f617e8  r14 000000000000380c  r15 000000000000380c
07-25 15:06:33.331 14391 14391 F DEBUG   :     rdi 000000000000380c  rsi 000000000000380c
07-25 15:06:33.331 14391 14391 F DEBUG   :     rbp 0000000000000e00  rsp 00007ffee8f616b0  rip 00007c9f438e0b90
07-25 15:06:33.331 14391 14391 F DEBUG   : 8 total frames
07-25 15:06:33.331 14391 14391 F DEBUG   : backtrace:
07-25 15:06:33.331 14391 14391 F DEBUG   :       #00 pc 000000000005cb90  /apex/com.android.runtime/lib64/bionic/libc.so (abort+192) (BuildId: eb58b4d427279994f00c0e1818477e4f)
07-25 15:06:33.332 14391 14391 F DEBUG   :       dotnet/runtime#1 pc 00000000000519a4  /data/app/~~9V1o6P8irnAlrqGQAZs_wg==/com.companyname.androidglobalizationrepro-jTqGYFNk8_VOZ6NJ_72RFA==/split_config.x86_64.apk!libmono-android.release.so (offset 0xd16000) (xamarin::android::Helpers::abort_application(bool, std::__ndk1::source_location)+68) (BuildId: bb24bad2340bfc0616b810f2f7ee15d4d085676a)
07-25 15:06:33.332 14391 14391 F DEBUG   :       dotnet/runtime#2 pc 000000000001fc8d  /data/app/~~9V1o6P8irnAlrqGQAZs_wg==/com.companyname.androidglobalizationrepro-jTqGYFNk8_VOZ6NJ_72RFA==/split_config.x86_64.apk!libmono-android.release.so (offset 0xd16000) (xamarin::android::internal::EmbeddedAssemblies::open_from_bundles(void*, _MonoAssemblyName*, char**, void*, _MonoError*)+8973) (BuildId: bb24bad2340bfc0616b810f2f7ee15d4d085676a)
07-25 15:06:33.332 14391 14391 F DEBUG   :       dotnet/runtime#3 pc 000000000024c3a3  /data/app/~~9V1o6P8irnAlrqGQAZs_wg==/com.companyname.androidglobalizationrepro-jTqGYFNk8_VOZ6NJ_72RFA==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0xd93000) (BuildId: 0a959315e0893aa7c032cbb6482832586a5811fb)
07-25 15:06:33.333 14391 14391 F DEBUG   :       dotnet/runtime#4 pc 00000000002495b9  /data/app/~~9V1o6P8irnAlrqGQAZs_wg==/com.companyname.androidglobalizationrepro-jTqGYFNk8_VOZ6NJ_72RFA==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0xd93000) (mono_assembly_request_byname+1177) (BuildId: 0a959315e0893aa7c032cbb6482832586a5811fb)
07-25 15:06:33.333 14391 14391 F DEBUG   :       dotnet/runtime#5 pc 0000000000246ee6  /data/app/~~9V1o6P8irnAlrqGQAZs_wg==/com.companyname.androidglobalizationrepro-jTqGYFNk8_VOZ6NJ_72RFA==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0xd93000) (BuildId: 0a959315e0893aa7c032cbb6482832586a5811fb)
07-25 15:06:33.333 14391 14391 F DEBUG   :       dotnet/runtime#6 pc 0000000000279ce4  /data/app/~~9V1o6P8irnAlrqGQAZs_wg==/com.companyname.androidglobalizationrepro-jTqGYFNk8_VOZ6NJ_72RFA==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0xd93000) (BuildId: 0a959315e0893aa7c032cbb6482832586a5811fb)
07-25 15:06:33.333 14391 14391 F DEBUG   :       dotnet/runtime#7 pc 0000000000016df3  <anonymous:4157b000>

Regression?

Yes, works with .NET preview 2

Known Workarounds

Use .NET 9 preview 2 or build the app on Mac.

Configuration

Other information

No response

dotnet-policy-service[bot] commented 1 month ago

Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger See info in area-owners.md if you want to be subscribed.

steveisok commented 1 month ago

Looks like it's somehow not respecting the culture you want:

looking for bundled name: 'cs-CZ/AndroidGlobalizationRepro.resources'

matouskozak commented 1 month ago

Looks like it's somehow not respecting the culture you want:

looking for bundled name: 'cs-CZ/AndroidGlobalizationRepro.resources'

Sorry, that's a mismatch in the issue description and the reported crash log. The cs-CZ is the desired culture in this case. Updated.

steveisok commented 1 month ago

Another question, is this a runtime issue or a xamarin-android one? Reason why I ask is they have a custom way of loading assemblies.

matouskozak commented 1 month ago

Another question, is this a runtime issue or a xamarin-android one? Reason why I ask is they have a custom way of loading assemblies.

I'm unsure on that. We had a big runtime change related to Globalization shipping after Preview 2 https://github.com/dotnet/runtime/pull/98495.

However, inspecting the binlogs from Preview 2 and Preview 5, I noticed that there are no entries for cs-CZ/AndroidGlobalizationRepro.resources in the Preview 2 log (the functioning app) whereas Preview 5 (broken app) reports multiple entries. This hints that there might have been changes on upper layer related to how localized resources are handled. @jonathanpeppers do you have any ideas on this?

jonathanpeppers commented 1 month ago

/cc @grendello maybe there is something going wrong with:

akoeplinger commented 1 month ago

Yeah it does feel more like a dotnet/android issue to me.

matouskozak commented 1 month ago

@jonathanpeppers @grendello would you like me to transfer the issue to dotnet/android?

grendello commented 1 month ago

@matouskozak yes, please. It does look like an issue with our app build process.