Skip to content

Commit f06ca0c

Browse files
authored
Merge pull request #155 from winnerspiros/fix/android-build-aot-trimming-12206102043476969963
Fix Android AOT build and .NET 10 trimming warnings
2 parents 9be39a3 + 784a5c0 commit f06ca0c

5 files changed

Lines changed: 25 additions & 1 deletion

File tree

osu.Android.props

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,17 @@
4242
Since Realm objects are not declared directly in Android projects, simply disable Fody. -->
4343
<DisableFody>true</DisableFody>
4444
</PropertyGroup>
45+
46+
<!-- WORKAROUND: Fix NativeAOT ILC failure on .NET 10 Android (early 2026 regression).
47+
The SDK incorrectly stamps AssetType="runtime" on non-DLL files (pdb, so, dbg)
48+
in the runtime pack, causing the AOT compiler to fail with BadImageFormatException.
49+
This target fixes the metadata before the SDK uses it.
50+
See: https://github.com/dotnet/runtime/pull/126214 -->
51+
<Target Name="FixRuntimePackAssetTypes" AfterTargets="_AddRuntimeLibsToPublishAssets" BeforeTargets="ComputeManagedAssembliesToCompileToNative">
52+
<ItemGroup>
53+
<RuntimePackAsset Condition="'%(Extension)' != '.dll'">
54+
<AssetType>native</AssetType>
55+
</RuntimePackAsset>
56+
</ItemGroup>
57+
</Target>
4558
</Project>

osu.Game/Configuration/SettingSourceAttribute.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
3+
using System.Diagnostics.CodeAnalysis;
34

45
using System;
56
using System.Collections.Concurrent;
@@ -42,6 +43,7 @@ public class SettingSourceAttribute : Attribute, IComparable<SettingSourceAttrib
4243
/// <remarks>
4344
/// Must be a type deriving <see cref="SettingsItem{T}"/> with a public parameterless constructor.
4445
/// </remarks>
46+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicProperties)]
4547
public Type? SettingControlType { get; set; }
4648

4749
public SettingSourceAttribute(Type declaringType, string label, string? description = null)
@@ -109,6 +111,9 @@ public int CompareTo(SettingSourceAttribute? other)
109111

110112
public static partial class SettingSourceExtensions
111113
{
114+
[UnconditionalSuppressMessage("Trimming", "IL2006", Justification = "The ModSettingsEnumDropdown is correctly generated for the bindable type.")]
115+
[UnconditionalSuppressMessage("Trimming", "IL2055", Justification = "The ModSettingsEnumDropdown is correctly generated for the bindable type.")]
116+
[UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "The ModSettingsEnumDropdown is correctly generated for the bindable type.")]
112117
public static IEnumerable<Drawable> CreateSettingsControls(this object obj)
113118
{
114119
foreach (var (attr, property) in obj.GetOrderedSettingsSourceProperties())
@@ -260,7 +265,7 @@ public static object GetUnderlyingSettingValue(this object setting)
260265
return properties;
261266
}
262267

263-
private static IEnumerable<(SettingSourceAttribute, PropertyInfo)> getSettingsSourceProperties(Type type)
268+
private static IEnumerable<(SettingSourceAttribute, PropertyInfo)> getSettingsSourceProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
264269
{
265270
foreach (var property in type.GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance))
266271
{

osu.Game/Database/BackgroundDataStoreProcessor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
3+
using System.Diagnostics.CodeAnalysis;
34

45
using System;
56
using System.Collections.Generic;
@@ -340,6 +341,7 @@ private void processBeatmapsWithMissingObjectCounts()
340341
completeNotification(notification, processedCount, beatmapIds.Count, failedCount);
341342
}
342343

344+
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The ScoreInfo.MaximumStatistics is already part of the trimming-safe path in Realm/Json serialization.")]
343345
private void processScoresWithMissingStatistics()
344346
{
345347
HashSet<Guid> scoreIds = new HashSet<Guid>();

osu.Game/IO/Serialization/SnakeCaseKeyContractResolver.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
3+
using System.Diagnostics.CodeAnalysis;
34

45
using Newtonsoft.Json.Serialization;
56
using osu.Game.Extensions;
67

78
namespace osu.Game.IO.Serialization
89
{
10+
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The contract resolver is correctly part of the reflection path for Newtonsoft.Json.")]
911
public class SnakeCaseKeyContractResolver : DefaultContractResolver
1012
{
1113
protected override string ResolvePropertyName(string propertyName)

osu.Game/Input/Bindings/DatabasedKeyBindingContainer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
3+
using System.Diagnostics.CodeAnalysis;
34

45
#nullable disable
56

@@ -49,6 +50,7 @@ public DatabasedKeyBindingContainer(RulesetInfo ruleset = null, int? variant = n
4950
throw new InvalidOperationException($"{nameof(variant)} can not be null when a non-null {nameof(ruleset)} is provided.");
5051
}
5152

53+
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Realm objects are safe for AsQueryable.")]
5254
protected override void LoadComplete()
5355
{
5456
realmSubscription = realm.RegisterForNotifications(queryRealmKeyBindings, (sender, _) =>

0 commit comments

Comments
 (0)