Skip to content

Commit 12f45d4

Browse files
authored
Merge pull request #162 from winnerspiros/fix-android-trimming-warnings-13825399711958778981
Resolve Android build warnings related to trimming and reflection
2 parents 2306409 + 161ebb7 commit 12f45d4

7 files changed

Lines changed: 40 additions & 53 deletions

File tree

Program.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
public class Host {
3+
public event Action? MyEvent;
4+
}
5+
public class Program {
6+
public static void Main() {
7+
Host? h = new Host();
8+
h?.MyEvent += () => {};
9+
}
10+
}

final_fix.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

osu.Android/Linker.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
</assembly>
1616
<assembly fullname="osu.Framework">
1717
<type fullname="osu.Framework.Audio.AudioManager">
18-
<field name="ActiveMixers" />
1918
<property name="ActiveMixers" />
2019
<field name="TrackMixer" />
2120
<field name="SampleMixer" />

osu.Android/OboeAudioRedirector.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public void RefreshMixers(int hardwareSampleRate)
102102
Console.WriteLine($"[osu!] Oboe redirector initialized successfully: master={masterMixer}, sources={string.Join(',', mixerHandles)}");
103103
}
104104

105-
[UnconditionalSuppressMessage("Trimming", "IL2067, IL2070, IL2072, IL2075, IL2106", Justification = "Preserved in Linker.xml")]
105+
// Trimming warnings suppressed because AudioManager.ActiveMixers and related types are manually preserved in Linker.xml.
106+
[UnconditionalSuppressMessage("Trimming", "IL2067, IL2070, IL2072, IL2075, IL2080, IL2106", Justification = "Preserved in Linker.xml")]
106107
private IEnumerable<AudioMixer> getActiveMixers()
107108
{
108109
Type type = typeof(AudioManager);
@@ -125,6 +126,24 @@ private IEnumerable<AudioMixer> getActiveMixers()
125126
}
126127
}
127128
}
129+
130+
foreach (var prop in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
131+
{
132+
if (prop.CanRead && prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericArguments().Contains(typeof(AudioMixer)))
133+
{
134+
object? val = prop.GetValue(audioManager);
135+
if (val is IEnumerable enumerable)
136+
{
137+
foreach (var item in enumerable)
138+
{
139+
if (item is AudioMixer mixer)
140+
yield return mixer;
141+
}
142+
yield break;
143+
}
144+
}
145+
}
146+
128147
type = type.BaseType!;
129148
}
130149
}
@@ -279,7 +298,8 @@ private void addMixer(AudioMixer? mixer)
279298
mixerHandles.Add(handle);
280299
}
281300

282-
[UnconditionalSuppressMessage("Trimming", "IL2067, IL2070, IL2072, IL2075, IL2106", Justification = "Preserved in Linker.xml")]
301+
// Trimming warnings suppressed because source handles (BASS mixer/stream/channel) are identified via reflection over types preserved in Linker.xml.
302+
[UnconditionalSuppressMessage("Trimming", "IL2067, IL2070, IL2072, IL2075, IL2080, IL2106", Justification = "Preserved in Linker.xml")]
283303
private int findHandle(object obj)
284304
{
285305
Type? type = obj.GetType();

osu.Android/OsuGameAndroid.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public OsuGameAndroid(OsuGameActivity activity)
6262
gameActivity = activity;
6363
}
6464

65-
[UnconditionalSuppressMessage("Trimming", "IL2067, IL2070, IL2072, IL2075, IL2106", Justification = "Preserved in Linker.xml")]
65+
// Trimming warnings suppressed because reflection is used to bind to AudioManager.ActiveMixers, which is manually preserved in Linker.xml.
66+
[UnconditionalSuppressMessage("Trimming", "IL2067, IL2070, IL2072, IL2075, IL2080, IL2106", Justification = "Preserved in Linker.xml")]
6667
protected override void LoadComplete()
6768
{
6869
base.LoadComplete();
@@ -391,7 +392,8 @@ public override void SetHost(GameHost host)
391392

392393
protected override BatteryInfo CreateBatteryInfo() => new AndroidBatteryInfo();
393394

394-
[UnconditionalSuppressMessage("Trimming", "IL2067, IL2070, IL2072, IL2075, IL2106", Justification = "Preserved in Linker.xml")]
395+
// Trimming warnings suppressed because reflection is used to unbind from AudioManager.ActiveMixers, which is manually preserved in Linker.xml.
396+
[UnconditionalSuppressMessage("Trimming", "IL2067, IL2070, IL2072, IL2075, IL2080, IL2106", Justification = "Preserved in Linker.xml")]
395397
protected override void Dispose(bool isDisposing)
396398
{
397399
try

osu.Game/Online/Spectator/SpectatorClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public void BeginPlaying(long? scoreToken, GameplayState state, Score score)
214214
Schedule(() =>
215215
{
216216
if (isPlaying)
217-
throw new InvalidOperationException($"Cannot invoke {nameof(BeginPlaying)} when already playing");
217+
return;
218218

219219
isPlaying = true;
220220

osu.Game/Screens/Play/HUD/HitErrorMeters/HitErrorMeter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
1+
// 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.
33

44
#nullable disable
@@ -18,7 +18,7 @@ public abstract partial class HitErrorMeter : CompositeDrawable, ISerialisableDr
1818
{
1919
protected HitWindows HitWindows { get; private set; }
2020

21-
[Resolved]
21+
[Resolved(canBeNull: true)]
2222
private ScoreProcessor processor { get; set; }
2323

2424
[Resolved]
@@ -44,7 +44,7 @@ protected override void LoadComplete()
4444

4545
gameplayClockContainer?.OnSeek += Clear;
4646

47-
processor.NewJudgement += processorNewJudgement;
47+
processor?.NewJudgement += processorNewJudgement;
4848
}
4949

5050
// Scheduled as meter implementations are likely going to change/add drawables when reacting to this.

0 commit comments

Comments
 (0)