Skip to content
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

[Xamarin.Android.Build.Tasks] fix <CilStrip/> for Hybrid AOT #4850

Merged
merged 1 commit into from
Jun 23, 2020
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
5 changes: 5 additions & 0 deletions Documentation/release-notes/4818.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#### Application and library build and deployment

* [GitHub 4818](https://github.com/xamarin/xamarin-android/issues/4818):
Applications using `AndroidAotMode=Hybrid` did not properly strip
away the IL from the resulting .NET assemblies.
Original file line number Diff line number Diff line change
Expand Up @@ -4331,5 +4331,37 @@ public void XA4310 ([Values ("apk", "aab")] string packageFormat)

}
}

[Test]
public void HybridAOT ()
{
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
AotAssemblies = true,
};
proj.SetProperty ("AndroidAotMode", "Hybrid");
// So we can use Mono.Cecil to open assemblies directly
proj.SetProperty ("AndroidEnableAssemblyCompression", "False");

using (var b = CreateApkBuilder ()) {
b.Build (proj);

var apk = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, $"{proj.PackageName}.apk");
FileAssert.Exists (apk);
using (var zip = ZipHelper.OpenZip (apk)) {
var entry = zip.ReadEntry ($"assemblies/{proj.ProjectName}.dll");
Assert.IsNotNull (entry, $"{proj.ProjectName}.dll should exist in apk!");
using (var stream = new MemoryStream ()) {
entry.Extract (stream);
stream.Position = 0;
using (var assembly = AssemblyDefinition.ReadAssembly (stream)) {
var type = assembly.MainModule.GetType ($"{proj.ProjectName}.MainActivity");
var method = type.Methods.First (m => m.Name == "OnCreate");
Assert.LessOrEqual (method.Body.Instructions.Count, 1, "OnCreate should have stripped method bodies!");
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,6 @@ public void BuildIncrementalAot (string supportedAbis, string androidAotMode, bo
Assert.IsFalse (b.Output.IsTargetSkipped (target), $"`{target}` should *not* be skipped on first build!");
}

if (androidAotMode == "Hybrid") {
// FIXME: with Hybrid AOT, <CilStrip/> modifies assemblies in-place
Assert.Ignore ("Ignoring, Hybrid AOT triggers _BuildApkEmbed.");
}

b.BuildLogFile = "second.log";
b.CleanupAfterSuccessfulBuild = false;
b.CleanupOnDispose = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2151,13 +2151,17 @@ because xbuild doesn't support framework reference assemblies.
<Output TaskParameter="NativeLibrariesReferences" ItemName="_AdditionalNativeLibraryReferences" />
</Aot>

<ItemGroup Condition=" '$(AndroidAotMode)' == 'Hybrid' And '$(AotAssemblies)' == 'True' ">
<_CilStripAssemblies Include="@(_ShrunkAssemblies)" Condition=" '%(FileName)' != 'Mono.Android' " />
</ItemGroup>

<!-- Strip the IL code of the resolved managed assemblies -->
<CilStrip
Condition=" '$(AndroidAotMode)' == 'Hybrid' And '$(AotAssemblies)' == 'True' "
AndroidAotMode="$(AndroidAotMode)"
ToolPath="$(_MonoAndroidToolsDirectory)"
ApkOutputPath="$(_BuildApkEmbedOutputs)"
ResolvedAssemblies="@(_ResolvedAssemblies)">
ResolvedAssemblies="@(_CilStripAssemblies)">
</CilStrip>

<!-- Bundle the assemblies into native libraries in the apk -->
Expand Down