Skip to content

Commit b90c559

Browse files
[trimmer] pass --disable-opt unusedtypechecks (#9435)
Fixes: #9399 An alternative to: #9411 The .NET trimmer will inline cast statements such as: var d = Application.Context.Resources.GetDrawable (resId); Assert.IsNotNull (d as NinePatchDrawable); If `NinePatchDrawable` is not "instantiated" anywhere via `new()`, then the above statements are rewritten/inlined to: var d = Application.Context.Resources.GetDrawable (resId); Assert.IsNotNull (null); // BOOM! We can solve this by passing `--disable-opt unusedtypechecks`, with `$(_AndroidEnableUnusedTypeChecks)` as a private MSBuild property to opt out if needed. Since Java can create these objects, this feels like the reasonable fix for .NET 9 GA. I also fixed the `$(RuntimeIdentifiers)` in `TestApks.targets` to check if someone passed `-r android-arm64`, for example.
1 parent 7516d54 commit b90c559

File tree

3 files changed

+2
-3
lines changed

3 files changed

+2
-3
lines changed

build-tools/scripts/TestApks.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<PropertyGroup>
2020
<!-- APK tests might run on 32-bit emulators -->
21-
<RuntimeIdentifiers>android-arm64;android-x86;android-x64;</RuntimeIdentifiers>
21+
<RuntimeIdentifiers Condition=" '$(RuntimeIdentifier)' == '' ">android-arm64;android-x86;android-x64;</RuntimeIdentifiers>
2222
<TestAvdApiLevel Condition=" '$(TestAvdApiLevel)' == '' ">29</TestAvdApiLevel>
2323
<TestAvdAbi Condition=" '$(TestAvdAbi)' == '' and '$(HostOS)' == 'Darwin' and '$(HostOSArchitecture)' == 'Arm64' ">arm64-v8a</TestAvdAbi>
2424
<TestAvdAbi Condition=" '$(TestAvdAbi)' == '' ">x86_64</TestAvdAbi>

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.ILLink.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This file contains the .NET 5-specific targets to customize ILLink
1616
<PropertyGroup>
1717
<TrimmerRemoveSymbols Condition=" '$(AndroidIncludeDebugSymbols)' != 'true' ">true</TrimmerRemoveSymbols>
1818
<_ExtraTrimmerArgs Condition=" '$(_EnableSerializationDiscovery)' != 'false' ">--enable-serialization-discovery $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs>
19+
<_ExtraTrimmerArgs Condition=" '$(_AndroidEnableUnusedTypeChecks)' != 'true' ">--disable-opt unusedtypechecks $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs>
1920
<!--
2021
Used for the <ILLink DumpDependencies="$(_TrimmerDumpDependencies)" /> value:
2122
https://github.com/dotnet/sdk/blob/a5393731b5b7b225692fff121f747fbbc9e8b140/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.ILLink.targets#L150

tests/Mono.Android-Tests/Android.Graphics/NinePatchTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public class NinePatchTests
2525
};
2626

2727
[Test, TestCaseSource (nameof (NinePatchDrawables))]
28-
[DynamicDependency (DynamicallyAccessedMemberTypes.All, typeof (NinePatchDrawable))]
2928
public void DrawableFromRes_ShouldBeTypeNinePatchDrawable (int resId, string name)
3029
{
3130
var d = Application.Context.Resources.GetDrawable (resId);
@@ -34,7 +33,6 @@ public void DrawableFromRes_ShouldBeTypeNinePatchDrawable (int resId, string nam
3433
}
3534

3635
[Test, TestCaseSource (nameof (NinePatchDrawables))]
37-
[DynamicDependency (DynamicallyAccessedMemberTypes.All, typeof (NinePatchDrawable))]
3836
public void DrawableFromResStream_ShouldBeTypeNinePatchDrawable (int resId, string name)
3937
{
4038
var value = new Android.Util.TypedValue ();

0 commit comments

Comments
 (0)