Skip to content

Commit df3317b

Browse files
committed
Include changes from PR #9452
1 parent 590b40b commit df3317b

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,20 @@ public override bool RunTask ()
6565

6666
// Set ShrunkAssemblies for _RemoveRegisterAttribute and <BuildApk/>
6767
// This should match the Condition on the _RemoveRegisterAttribute target
68-
if (PublishTrimmed && !AndroidIncludeDebugSymbols) {
69-
var shrunkAssemblies = new List<ITaskItem> (OutputAssemblies.Length);
70-
foreach (var assembly in OutputAssemblies) {
71-
var dir = Path.GetDirectoryName (assembly.ItemSpec);
72-
var file = Path.GetFileName (assembly.ItemSpec);
73-
shrunkAssemblies.Add (new TaskItem (assembly) {
74-
ItemSpec = Path.Combine (dir, "shrunk", file),
75-
});
68+
if (PublishTrimmed) {
69+
if (!AndroidIncludeDebugSymbols) {
70+
var shrunkAssemblies = new List<ITaskItem> (OutputAssemblies.Length);
71+
foreach (var assembly in OutputAssemblies) {
72+
var dir = Path.GetDirectoryName (assembly.ItemSpec);
73+
var file = Path.GetFileName (assembly.ItemSpec);
74+
shrunkAssemblies.Add (new TaskItem (assembly) {
75+
ItemSpec = Path.Combine (dir, "shrunk", file),
76+
});
77+
}
78+
ShrunkAssemblies = shrunkAssemblies.ToArray ();
79+
} else {
80+
ShrunkAssemblies = OutputAssemblies;
7681
}
77-
ShrunkAssemblies = shrunkAssemblies.ToArray ();
7882
}
7983

8084
if (InputJavaLibraries != null) {

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,31 @@ public void CheckR8InfoMessagesToNotBreakTheBuild ()
5656
}
5757
}
5858

59+
[Test]
60+
public void CheckDebugModeWithTrimming ()
61+
{
62+
bool usesAssemblyStores = false;
63+
var proj = new XamarinAndroidApplicationProject {
64+
ProjectName = "MyApp",
65+
IsRelease = false,
66+
EmbedAssembliesIntoApk = true,
67+
};
68+
proj.SetProperty ("PublishTrimmed", "true");
69+
proj.SetProperty ("AndroidUseAssemblyStore", usesAssemblyStores.ToString ());
70+
71+
using var b = CreateApkBuilder ();
72+
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
73+
74+
var apk = Path.Combine (Root, b.ProjectDirectory,
75+
proj.OutputPath, $"{proj.PackageName}-Signed.apk");
76+
var helper = new ArchiveAssemblyHelper (apk, usesAssemblyStores);
77+
helper.Contains (["Mono.Android.dll", $"{proj.ProjectName}.dll"], out _, out var missingFiles, out _, [AndroidTargetArch.Arm64, AndroidTargetArch.X86_64]);
78+
79+
Assert.IsTrue (missingFiles == null || missingFiles.Count == 0,
80+
string.Format ("The following Expected files are missing. {0}",
81+
string.Join (Environment.NewLine, missingFiles)));
82+
}
83+
5984
[Test]
6085
[NonParallelizable] // Commonly fails NuGet restore
6186
public void CheckIncludedAssemblies ([Values (false, true)] bool usesAssemblyStores)

0 commit comments

Comments
 (0)