dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 532 forks source link

[Build.Tasks] Better handle gradle project custom output paths #9480

Closed pjcollins closed 2 weeks ago

pjcollins commented 2 weeks ago

The AndroidGradleProject targets have been updated to fix some issues we ran into when trying to use this new build action in the MAUI build.

The default output path property will now check to see if it is rooted before adding a $(MSBuildProjectDirectory) prefix to make it an absolute path. The property name has also been shortened. This fixes projects/builds that set $(BaseIntermediateOutputPath) or $(IntermediateOutputPath) to an absolute path that would hit an error along the lines of:

D:\a\_work\1\s\.dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.0-rc.2.152\tools\Microsoft.Android.Sdk.Bindings.Gradle.targets(73,5): error XACPR7024: System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. : 'D:\a\_work\1\s\src\Core\src\D:\a\_work\1\s\artifacts\obj\Core\Release\net9.0-android35.0\gradle'.

Projects which set the %(AndroidGradleProject.OutputPath) metadata to use a custom gradle output path have been fixed to ensure a trailing slash is always used.

While looking through binlogs I also noticed the following message:

MSB4120: Item '_AndroidGradleProjectLibraryOutputs' definition within target references itself via (qualified or unqualified) metadatum 'Bind'. This can lead to unintended expansion and cross-applying of pre-existing items. More info: https://aka.ms/msbuild/metadata-self-ref

This has been fixed by qualifying the metadata that is added when creating @(_AndroidGradleProjectLibraryOutputs) items.

A test has also been added for $(UseArtifactsOutput): https://learn.microsoft.com/dotnet/core/sdk/artifacts-output