Skip to content

Commit f149c25

Browse files
[Xamarin.Android.Build.Tasks] fix @(LibraryProjectZip) and NuGets (#7151)
Context: xamarin/GooglePlayServicesComponents#652 In .NET 6, `@(AndroidLibrary.Pack)` defaults to true (97190b6), while `%(LibraryProjectZip.Pack)` was never set, and thus was false. This would be an issue if you migrated a project using `@(LibraryProjectZip)` and were not relying on the default wildcards used by: <AndroidLibrary Include="**/*.aar" /> The result is that `.aar` files weren't included into the `.nupkg`, which would result in subsequent build & packaging errors when using the `.nupkg`, as the `.aar` was missing. Set `%(LibraryProjectZip.Pack)`=True by default in .NET 6+, to ease project migration from Classic Xamarin.Android to .NET 6. I updated a test for this scenario and fixed some assertions that are working since 2ca2a10 was merged.
1 parent dbadf13 commit f149c25

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.AvailableItems.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ This item group populates the Build Action drop-down in IDEs.
6666
<Bind>true</Bind>
6767
<Pack Condition=" '$(UsingAndroidNETSdk)' == 'true' ">true</Pack>
6868
</AndroidLibrary>
69+
<LibraryProjectZip>
70+
<Pack Condition=" '$(UsingAndroidNETSdk)' == 'true' ">true</Pack>
71+
</LibraryProjectZip>
6972
<AndroidJavaSource>
7073
<Bind Condition=" '$(UsingAndroidNETSdk)' == 'true' ">true</Bind>
7174
</AndroidJavaSource>

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ public String Say (String quote) {
304304
MetadataValues = "Link=x86\\libfoo.so",
305305
BinaryContent = () => Array.Empty<byte> (),
306306
});
307+
proj.OtherBuildItems.Add (new AndroidItem.LibraryProjectZip ("..\\baz.aar") {
308+
WebContent = "https://repo1.maven.org/maven2/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar",
309+
MetadataValues = "Bind=false",
310+
});
307311
proj.OtherBuildItems.Add (new AndroidItem.AndroidLibrary (default (Func<string>)) {
308312
Update = () => "nopack.aar",
309313
WebContent = "https://repo1.maven.org/maven2/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar",
@@ -318,16 +322,17 @@ public String Say (String quote) {
318322
using var nupkg = ZipHelper.OpenZip (nupkgPath);
319323
nupkg.AssertContainsEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/{proj.ProjectName}.dll");
320324
nupkg.AssertContainsEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/{proj.ProjectName}.aar");
321-
325+
nupkg.AssertContainsEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/bar.aar");
326+
nupkg.AssertDoesNotContainEntry (nupkgPath, "content/bar.aar");
327+
nupkg.AssertDoesNotContainEntry (nupkgPath, "content/sub/directory/bar.aar");
328+
nupkg.AssertDoesNotContainEntry (nupkgPath, $"contentFiles/any/{dotnetVersion}-android{apiLevel}.0/sub/directory/bar.aar");
329+
nupkg.AssertDoesNotContainEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/nopack.aar");
330+
nupkg.AssertDoesNotContainEntry (nupkgPath, "content/nopack.aar");
331+
nupkg.AssertDoesNotContainEntry (nupkgPath, $"contentFiles/any/{dotnetVersion}-android{apiLevel}.0/nopack.aar");
332+
333+
//TODO: this issue is not fixed in net6.0-android MSBuild targets
322334
if (dotnetVersion != "net6.0") {
323-
//TODO: this issue is not fixed in net6.0-android MSBuild targets
324-
nupkg.AssertContainsEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/bar.aar");
325-
nupkg.AssertDoesNotContainEntry (nupkgPath, "content/bar.aar");
326-
nupkg.AssertDoesNotContainEntry (nupkgPath, "content/sub/directory/bar.aar");
327-
nupkg.AssertDoesNotContainEntry (nupkgPath, $"contentFiles/any/{dotnetVersion}-android{apiLevel}.0/sub/directory/bar.aar");
328-
nupkg.AssertDoesNotContainEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/nopack.aar");
329-
nupkg.AssertDoesNotContainEntry (nupkgPath, "content/nopack.aar");
330-
nupkg.AssertDoesNotContainEntry (nupkgPath, $"contentFiles/any/{dotnetVersion}-android{apiLevel}.0/nopack.aar");
335+
nupkg.AssertContainsEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/baz.aar");
331336
}
332337
}
333338

0 commit comments

Comments
 (0)