Skip to content

[xabt] remove $(AndroidStripILAfterAOT) #10204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ This means that in Release configuration builds -- in which
This can result in increased app sizes. This behavior can be overridden by explicitly setting
`$(AndroidEnableProfiledAot)` to `true` within your project file.

Support for this property was added in .NET 8.
Experimental support for this property was added in .NET 8, removed in .NET 10.

## AndroidSupportedAbis

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,50 +137,14 @@ They run in a context of an inner build with a single $(RuntimeIdentifier).
LLVMPath="$(_LLVMPath)"
LdName="$(_LdName)"
LdFlags="$(_LdFlags)"
CollectTrimmingEligibleMethods="$(AndroidStripILAfterAOT)"
CollectTrimmingEligibleMethods="$(_AndroidCollectTrimmingEligibleMethods)"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a private property, $(_AndroidCollectTrimmingEligibleMethods), if someone wants to experiment with this in the future. This way it's possible to set it.

TrimmingEligibleMethodsOutputDirectory="$(IntermediateOutputPath)tokens"
WorkingDirectory="$(MSBuildProjectDirectory)"
AotArguments="$(AndroidAotAdditionalArguments)">
<Output TaskParameter="CompiledAssemblies" ItemName="_MonoAOTCompiledAssemblies" />
<Output TaskParameter="FileWrites" ItemName="FileWrites" />
</MonoAOTCompiler>
<ILStrip
Condition=" '$(AndroidStripILAfterAOT)' == 'true' "
TrimIndividualMethods="true"
Assemblies="@(_MonoAOTCompiledAssemblies)"
IntermediateOutputPath="$(IntermediateOutputPath)"
DisableParallelStripping="$(_DisableParallelAot)">
<Output TaskParameter="UpdatedAssemblies" ItemName="_ILStripUpdatedAssemblies" />
</ILStrip>
<Copy
Condition=" '$(AndroidStripILAfterAOT)' == 'true' and '%(_ILStripUpdatedAssemblies.ILStripped)' == 'true' and '%(_ILStripUpdatedAssemblies.UntrimmedAssemblyFilePath)' != '' "
SourceFiles="@(_ILStripUpdatedAssemblies)"
DestinationFiles="@(_ILStripUpdatedAssemblies->'%(UntrimmedAssemblyFilePath)')"
/>
<ItemGroup>
<_UpdateStamp Include="@(_ILStripUpdatedAssemblies)" Condition=" '$(AndroidStripILAfterAOT)' == 'true' and '%(_ILStripUpdatedAssemblies.ILStripped)' == 'true' " />
</ItemGroup>

<!-- We must update the stamp file used by `_GenerateJavaStubs`, but `$(_AndroidStampDirectory)` **here** is inside a per-RID parent
directory (e.g. `obj/Release/android-arm64/stamp`) and not the "top level" one (`obj/Release/stamp`). Since **both** are set
in the same place (in `Xamarin.Android.Common.targets`), we don't know where the "top level" one really is. Hence the hack.
If the locations or their relative paths change, then the `EnableAndroidStripILAfterAOTFalse` test will fail.

However, there should be a better way to do it... Ideally, when marshal methods are enabled **nothing** should modify any
assemblies after marshal method classifier and rewriter runs.
-->
<PropertyGroup>
<_StampDir>$(_AndroidStampDirectory)\..\..\stamp</_StampDir>
</PropertyGroup>
<MakeDir
Condition=" '$(AndroidStripILAfterAOT)' == 'true' and '@(_UpdateStamp->Count())' &gt; 0 "
Directories="$(_StampDir)"
/>
<Touch
Condition=" '$(AndroidStripILAfterAOT)' == 'true' and '@(_UpdateStamp->Count())' &gt; 0 "
Files="$(_StampDir)\_GenerateJavaStubs.stamp"
AlwaysCreate="True"
/>
<WriteLinesToFile
File="$(_AndroidStampDirectory)_AndroidAot.stamp"
Lines="@(_MonoAOTCompiledAssemblies->'%(LibraryFile)')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<_AndroidXA1029 Condition=" '$(AotAssemblies)' != '' ">true</_AndroidXA1029>
<_AndroidXA1030 Condition=" '$(RunAOTCompilation)' == 'true' and '$(PublishTrimmed)' == 'false' ">true</_AndroidXA1030>
<AotAssemblies>$(RunAOTCompilation)</AotAssemblies>
<AndroidEnableProfiledAot Condition=" '$(AndroidEnableProfiledAot)' == '' and '$(RunAOTCompilation)' == 'true' and '$(AndroidStripILAfterAOT)' != 'true' ">true</AndroidEnableProfiledAot>
<AndroidEnableProfiledAot Condition=" '$(AndroidEnableProfiledAot)' == '' and '$(RunAOTCompilation)' == 'true' ">true</AndroidEnableProfiledAot>

<!--
Runtime libraries feature switches defaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,7 @@ because xbuild doesn't support framework reference assemblies.

<!-- Shrink Mono.Android.dll by removing attribute only needed for GenerateJavaStubs -->
<RemoveRegisterAttribute
Condition="'$(AndroidLinkMode)' != 'None' and '$(AndroidIncludeDebugSymbols)' != 'true' and '$(AndroidStripILAfterAOT)' != 'true' and '$(_AndroidRuntime)' != 'NativeAOT' and '$(PublishReadyToRun)' != 'true' "
Condition="'$(AndroidLinkMode)' != 'None' and '$(AndroidIncludeDebugSymbols)' != 'true' and '$(_AndroidRuntime)' != 'NativeAOT' and '$(PublishReadyToRun)' != 'true' "
ShrunkFrameworkAssemblies="@(_ShrunkAssemblies)" />

<MakeDir Directories="$(MonoAndroidIntermediateAssemblyDir)shrunk" />
Expand Down
38 changes: 0 additions & 38 deletions tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,44 +1087,6 @@ public void FastDeployEnvironmentFiles (bool isRelease, bool embedAssembliesInto
}
}

[Test]
public void EnableAndroidStripILAfterAOT ([Values (false, true)] bool profiledAOT)
{
var proj = new XamarinAndroidApplicationProject {
ProjectName = nameof (EnableAndroidStripILAfterAOT),
RootNamespace = nameof (EnableAndroidStripILAfterAOT),
IsRelease = true,
EnableDefaultItems = true,
};
proj.SetProperty("AndroidStripILAfterAOT", "true");
proj.SetProperty("AndroidEnableProfiledAot", profiledAOT.ToString ());
// So we can use Mono.Cecil to open assemblies directly
proj.SetProperty ("AndroidEnableAssemblyCompression", "false");

var builder = CreateApkBuilder ();
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed");

var apk = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.PackageName}-Signed.apk");
FileAssert.Exists (apk);
var helper = new ArchiveAssemblyHelper (apk);
Assert.IsTrue (helper.Exists ($"assemblies/{proj.ProjectName}.dll"), $"{proj.ProjectName}.dll should exist in apk!");
using (var stream = helper.ReadEntry ($"assemblies/{proj.ProjectName}.dll")) {
stream.Position = 0;
using var assembly = AssemblyDefinition.ReadAssembly (stream);
var type = assembly.MainModule.GetType ($"{proj.RootNamespace}.MainActivity");
var method = type.Methods.FirstOrDefault (p => p.Name == "OnCreate");
Assert.IsNotNull (method, $"{proj.RootNamespace}.MainActivity.OnCreate should exist!");
Assert.IsTrue (!method.HasBody || method.Body.Instructions.Count == 0, $"{proj.RootNamespace}.MainActivity.OnCreate should have no body!");
}

RunProjectAndAssert (proj, builder);

WaitForPermissionActivity (Path.Combine (Root, builder.ProjectDirectory, "permission-logcat.log"));
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity",
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30);
Assert.IsTrue(didLaunch, "Activity should have started.");
}

[Test]
public void FixLegacyResourceDesignerStep ([Values (true, false)] bool isRelease)
{
Expand Down
Loading