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

[release/6.0.4xx] [One .NET] pack AndroidLibrary .aar files in .nupkg #7053

Merged
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 @@ -97,7 +97,7 @@ This item group populates the Build Action drop-down in IDEs.
<AndroidJavaLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' and '%(AndroidLibrary.Bind)' != 'true' " />
<EmbeddedJar Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' and '%(AndroidLibrary.Bind)' == 'true' " />
<!-- .aar files should be copied to $(OutputPath) in .NET 6-->
<None Include="@(LibraryProjectZip)" CopyToOutputDirectory="PreserveNewest" Link="%(Filename)%(Extension)" />
<None Include="@(LibraryProjectZip)" TfmSpecificPackageFile="%(LibraryProjectZip.Pack)" Pack="false" CopyToOutputDirectory="PreserveNewest" Link="%(Filename)%(Extension)" />
</ItemGroup>
<!-- Legacy binding projects -->
<ItemGroup Condition=" '$(_AndroidIsBindingProject)' == 'true' and '$(UsingAndroidNETSdk)' != 'true' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ projects.
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_IncludeAarInNuGetPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="_IncludeAarInNuGetPackage"
Condition=" '$(IncludeBuildOutput)' != 'false' and '$(AndroidApplication)' != 'true' and Exists('$(_AarOutputPath)') ">
Condition=" '$(IncludeBuildOutput)' != 'false' and '$(AndroidApplication)' != 'true' "
DependsOnTargets="_CategorizeAndroidLibraries">
<GetNuGetShortFolderName
TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
TargetPlatformMoniker="$(TargetPlatformMoniker)">
<Output TaskParameter="NuGetShortFolderName" PropertyName="_NuGetShortFolderName" />
</GetNuGetShortFolderName>
<ItemGroup>
<TfmSpecificPackageFile Include="$(_AarOutputPath)" PackagePath="lib\$(_NuGetShortFolderName)" />
<TfmSpecificPackageFile Condition="Exists('$(_AarOutputPath)')" Include="$(_AarOutputPath)" PackagePath="lib\$(_NuGetShortFolderName)" />
<TfmSpecificPackageFileWithRecursiveDir Include="@(None->WithMetadataValue ('TfmSpecificPackageFile', 'true'))" PackagePath="lib\$(_NuGetShortFolderName)" NuGetRecursiveDir="" />
</ItemGroup>
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,30 @@ public Foo ()
TextContent = () => {
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ImageView xmlns:android=\"http://schemas.android.com/apk/res/android\" android:src=\"@drawable/IMALLCAPS\" />";
}
}
},
new AndroidItem.AndroidAsset ("Assets\\foo\\foo.txt") {
BinaryContent = () => Array.Empty<byte> (),
},
new AndroidItem.AndroidResource ("Resources\\layout\\MyLayout.axml") {
TextContent = () => "<?xml version=\"1.0\" encoding=\"utf-8\" ?><LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" />"
},
new AndroidItem.AndroidResource ("Resources\\raw\\bar.txt") {
BinaryContent = () => Array.Empty<byte> (),
},
new AndroidItem.AndroidLibrary ("sub\\directory\\foo.jar") {
BinaryContent = () => ResourceData.JavaSourceJarTestJar,
},
new AndroidItem.AndroidLibrary ("sub\\directory\\bar.aar") {
WebContent = "https://repo1.maven.org/maven2/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar",
},
}
};
libB.OtherBuildItems.Add (new AndroidItem.AndroidAsset ("Assets\\foo\\foo.txt") {
BinaryContent = () => Array.Empty<byte> (),
});
libB.OtherBuildItems.Add (new AndroidItem.AndroidResource ("Resources\\layout\\MyLayout.axml") {
TextContent = () => "<?xml version=\"1.0\" encoding=\"utf-8\" ?><LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" />"
});
libB.OtherBuildItems.Add (new AndroidItem.AndroidResource ("Resources\\raw\\bar.txt") {
BinaryContent = () => Array.Empty<byte> (),
});
libB.OtherBuildItems.Add (new AndroidItem.AndroidEnvironment ("env.txt") {
TextContent = () => $"{env_var}={env_val}",
});
libB.OtherBuildItems.Add (new AndroidItem.AndroidEnvironment ("sub\\directory\\env.txt") {
TextContent = () => $"{env_var}={env_val}",
});
libB.OtherBuildItems.Add (new AndroidItem.AndroidLibrary ("sub\\directory\\foo.jar") {
BinaryContent = () => ResourceData.JavaSourceJarTestJar,
});
libB.OtherBuildItems.Add (new AndroidItem.AndroidLibrary ("sub\\directory\\arm64-v8a\\libfoo.so") {
BinaryContent = () => Array.Empty<byte> (),
});
Expand All @@ -127,8 +130,10 @@ public Foo ()
Assert.IsTrue (libBBuilder.Build (), $"{libB.ProjectName} should succeed");

// Check .aar file for class library
var aarPath = Path.Combine (FullProjectDirectory, libB.OutputPath, $"{libB.ProjectName}.aar");
var libBOutputPath = Path.Combine (FullProjectDirectory, libB.OutputPath);
var aarPath = Path.Combine (libBOutputPath, $"{libB.ProjectName}.aar");
FileAssert.Exists (aarPath);
FileAssert.Exists (Path.Combine (libBOutputPath, "bar.aar"));
using (var aar = ZipHelper.OpenZip (aarPath)) {
aar.AssertContainsEntry (aarPath, "assets/foo/foo.txt");
aar.AssertContainsEntry (aarPath, "res/layout/mylayout.xml");
Expand Down Expand Up @@ -237,18 +242,21 @@ public void DotNetPack (string targetFramework, int apiLevel)
Sources = {
new BuildItem.Source ("Foo.cs") {
TextContent = () => "public class Foo { }",
}
}
},
new AndroidItem.AndroidResource ("Resources\\raw\\bar.txt") {
BinaryContent = () => Array.Empty<byte> (),
},
new AndroidItem.AndroidLibrary ("sub\\directory\\foo.jar") {
BinaryContent = () => ResourceData.JavaSourceJarTestJar,
},
new AndroidItem.AndroidLibrary ("sub\\directory\\bar.aar") {
WebContent = "https://repo1.maven.org/maven2/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar",
},
},
};
if (IsPreviewFrameworkVersion (targetFramework)) {
proj.SetProperty ("EnablePreviewFeatures", "true");
}
proj.OtherBuildItems.Add (new AndroidItem.AndroidResource ("Resources\\raw\\bar.txt") {
BinaryContent = () => Array.Empty<byte> (),
});
proj.OtherBuildItems.Add (new AndroidItem.AndroidLibrary ("sub\\directory\\foo.jar") {
BinaryContent = () => ResourceData.JavaSourceJarTestJar,
});
proj.OtherBuildItems.Add (new AndroidItem.AndroidLibrary ("sub\\directory\\arm64-v8a\\libfoo.so") {
BinaryContent = () => Array.Empty<byte> (),
});
Expand All @@ -257,16 +265,29 @@ public void DotNetPack (string targetFramework, int apiLevel)
MetadataValues = "Link=x86\\libfoo.so",
BinaryContent = () => Array.Empty<byte> (),
});
proj.OtherBuildItems.Add (new AndroidItem.AndroidLibrary (default (Func<string>)) {
Update = () => "nopack.aar",
WebContent = "https://repo1.maven.org/maven2/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar",
MetadataValues = "Pack=false;Bind=false",
});

const string dotnetVersion = "net6.0";
var dotnet = CreateDotNetBuilder (proj);
Assert.IsTrue (dotnet.Pack (), "`dotnet pack` should succeed");

var nupkgPath = Path.Combine (FullProjectDirectory, proj.OutputPath, "..", $"{proj.ProjectName}.1.0.0.nupkg");
FileAssert.Exists (nupkgPath);
using (var nupkg = ZipHelper.OpenZip (nupkgPath)) {
nupkg.AssertContainsEntry (nupkgPath, $"lib/net6.0-android{apiLevel}.0/{proj.ProjectName}.dll");
nupkg.AssertContainsEntry (nupkgPath, $"lib/net6.0-android{apiLevel}.0/{proj.ProjectName}.aar");
}
using var nupkg = ZipHelper.OpenZip (nupkgPath);
nupkg.AssertContainsEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/{proj.ProjectName}.dll");
nupkg.AssertContainsEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/{proj.ProjectName}.aar");

nupkg.AssertContainsEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/bar.aar");
nupkg.AssertDoesNotContainEntry (nupkgPath, "content/bar.aar");
nupkg.AssertDoesNotContainEntry (nupkgPath, "content/sub/directory/bar.aar");
nupkg.AssertDoesNotContainEntry (nupkgPath, $"contentFiles/any/{dotnetVersion}-android{apiLevel}.0/sub/directory/bar.aar");
nupkg.AssertDoesNotContainEntry (nupkgPath, $"lib/{dotnetVersion}-android{apiLevel}.0/nopack.aar");
nupkg.AssertDoesNotContainEntry (nupkgPath, "content/nopack.aar");
nupkg.AssertDoesNotContainEntry (nupkgPath, $"contentFiles/any/{dotnetVersion}-android{apiLevel}.0/nopack.aar");
}

[Test]
Expand Down