Skip to content
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
22 changes: 13 additions & 9 deletions src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,20 @@ public override bool RunTask ()

// Set ShrunkAssemblies for _RemoveRegisterAttribute and <BuildApk/>
// This should match the Condition on the _RemoveRegisterAttribute target
if (PublishTrimmed && !AndroidIncludeDebugSymbols) {
var shrunkAssemblies = new List<ITaskItem> (OutputAssemblies.Length);
foreach (var assembly in OutputAssemblies) {
var dir = Path.GetDirectoryName (assembly.ItemSpec);
var file = Path.GetFileName (assembly.ItemSpec);
shrunkAssemblies.Add (new TaskItem (assembly) {
ItemSpec = Path.Combine (dir, "shrunk", file),
});
if (PublishTrimmed) {
if (!AndroidIncludeDebugSymbols) {
var shrunkAssemblies = new List<ITaskItem> (OutputAssemblies.Length);
foreach (var assembly in OutputAssemblies) {
var dir = Path.GetDirectoryName (assembly.ItemSpec);
var file = Path.GetFileName (assembly.ItemSpec);
shrunkAssemblies.Add (new TaskItem (assembly) {
ItemSpec = Path.Combine (dir, "shrunk", file),
});
}
ShrunkAssemblies = shrunkAssemblies.ToArray ();
} else {
ShrunkAssemblies = OutputAssemblies;
}
ShrunkAssemblies = shrunkAssemblies.ToArray ();
}

if (InputJavaLibraries != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ public void CheckR8InfoMessagesToNotBreakTheBuild ()
}
}

[Test]
public void CheckDebugModeWithTrimming ()
{
bool usesAssemblyStores = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you want to make this a parameter? The value never changes from false.

Copy link
Member Author

Choose a reason for hiding this comment

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

The test didn't work with true, it doesn't seem to find any assembly stores. This could be another bug? But I manually checked and saw the assemblies inside.

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't find any assembly stores because there are no assemblies in the build (the _Shrunk* item groups are empty)

Copy link
Member Author

Choose a reason for hiding this comment

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

This change fixes the @(_Shrunk*) item groups, I see them inside the _PrepareAssemblies target now:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Must be with FastDev enabled, because without it I don't see the _Shrunk* groups populated :(

var proj = new XamarinAndroidApplicationProject {
ProjectName = "MyApp",
IsRelease = false,
EmbedAssembliesIntoApk = true,
};
proj.SetProperty ("PublishTrimmed", "true");
proj.SetProperty ("AndroidUseAssemblyStore", usesAssemblyStores.ToString ());

using var b = CreateApkBuilder ();
Assert.IsTrue (b.Build (proj), "build should have succeeded.");

var apk = Path.Combine (Root, b.ProjectDirectory,
proj.OutputPath, $"{proj.PackageName}-Signed.apk");
var helper = new ArchiveAssemblyHelper (apk, usesAssemblyStores);
helper.Contains (["Mono.Android.dll", $"{proj.ProjectName}.dll"], out _, out var missingFiles, out _, [AndroidTargetArch.Arm64, AndroidTargetArch.X86_64]);

Assert.IsTrue (missingFiles == null || missingFiles.Count == 0,
string.Format ("The following Expected files are missing. {0}",
string.Join (Environment.NewLine, missingFiles)));
}

[Test]
[NonParallelizable] // Commonly fails NuGet restore
public void CheckIncludedAssemblies ([Values (false, true)] bool usesAssemblyStores)
Expand Down
Loading