Skip to content

Commit a65c31b

Browse files
authored
Merge pull request #109 from winnerspiros/copilot/fix-osu-android-crash
Fix Android runtime crash: MAUI Platform.Init + document framework TFM fallback
2 parents 5928f68 + c2a0df1 commit a65c31b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

osu.Android.props

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<RuntimeIdentifiers>android-x86;android-arm;android-arm64</RuntimeIdentifiers>
55
<AndroidPackageFormat>apk</AndroidPackageFormat>
66
<MandroidI18n>CJK;Mideast;Rare;West;Other;</MandroidI18n>
7-
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidMessageHandler, Mono.Android</AndroidHttpClientHandlerType>
7+
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidMessageHandler</AndroidHttpClientHandlerType>
88
<!-- NullabilityInfoContextSupport is disabled by default for Android -->
99
<NullabilityInfoContextSupport>true</NullabilityInfoContextSupport>
1010
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
@@ -26,6 +26,11 @@
2626
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
2727
</PropertyGroup>
2828
<ItemGroup>
29+
<!-- IMPORTANT: ppy.osu.Framework.Android v2026.318.0 only ships net8.0-android34.0 assets.
30+
NuGet silently falls back to those assets when the app targets net10.0-android (API 36).
31+
This is safe because .NET guarantees backward compatibility for loading net8.0 assemblies
32+
in a net10.0 runtime, and Android API changes between 34→36 are additive.
33+
TODO: Remove this comment once ppy.osu.Framework.Android ships net10.0-android assets. -->
2934
<PackageReference Include="ppy.osu.Framework.Android" Version="2026.318.0" />
3035
</ItemGroup>
3136
<PropertyGroup>

osu.Android/OsuGameActivity.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ protected override void OnCreate(Bundle? savedInstanceState)
7373
{
7474
base.OnCreate(savedInstanceState);
7575

76+
// Initialise MAUI Essentials so that Battery, Connectivity and other platform
77+
// APIs can resolve the current Activity/context. Without this call the
78+
// BroadcastReceivers registered in the merged manifest (BatteryBroadcastReceiver,
79+
// EnergySaverBroadcastReceiver, ConnectivityBroadcastReceiver) will crash on
80+
// first use because the internal Platform.CurrentActivity is null.
81+
Microsoft.Maui.ApplicationModel.Platform.Init(this, savedInstanceState);
82+
7683
// OnNewIntent() only fires for an activity if it's *re-launched* while it's on top of the activity stack.
7784
// on first launch we still have to fire manually.
7885
// reference: https://developer.android.com/reference/android/app/Activity#onNewIntent(android.content.Intent)
@@ -116,6 +123,12 @@ protected override void OnCreate(Bundle? savedInstanceState)
116123

117124
protected override void OnNewIntent(Intent? intent) => handleIntent(intent);
118125

126+
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
127+
{
128+
Microsoft.Maui.ApplicationModel.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
129+
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
130+
}
131+
119132
private void handleIntent(Intent? intent)
120133
{
121134
if (intent == null)

0 commit comments

Comments
 (0)