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

$(AndroidStripILAfterAOT)=true tries to overwrite files it shouldn't #9577

Open
jonpryor opened this issue Dec 3, 2024 · 3 comments
Open
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@jonpryor
Copy link
Member

jonpryor commented Dec 3, 2024

Android framework version

net8.0-android, net9.0-android

Affected platform version

.NET 8+

Description

If you build a project with $(RunAOTCompilation)=true and $(AndroidStripILAfterAOT)=true, and .NET is installed into a non-user-writable location (e.g. /usr/local on macOS, owned by root):

dotnet new android -n net9-android-filewrite
cd net9-android-filewrite
dotnet build -bl -p:RunAOTCompilation=true -p:AndroidStripILAfterAOT=true

then the build will fail:

/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/35.0.7/targets/Microsoft.Android.Sdk.Aot.targets(142,5):
error MSB3021: Unable to copy file "obj/Debug/net9.0-android/android-x64/stripped/Microsoft.CSharp.dll" to "/usr/local/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.android-x64/9.0.0/runtimes/android-x64/lib/net9.0/Microsoft.CSharp.dll".
Access to the path '/usr/local/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.android-x64/9.0.0/runtimes/android-x64/lib/net9.0/Microsoft.CSharp.dll' is denied.

This is concerning because it could work! I have a separate .NET 8 install in $HOME/Downloads/dotnet-sdk-8.0.206-osx-x64, and building a .NET 8 project with this .NET install with these properties set worked:

$HOME/Downloads/dotnet-sdk-8.0.206-osx-x64/dotnet build -bl -p:RunAOTCompilation=true -p:AndroidStripILAfterAOT=true

The binlog contains:

Moving file from "…/obj/Debug/net8.0-android/android-arm64/aot-in/System.Private.Xml_trimmed.dll" to "$HOME/Downloads/dotnet-sdk-8.0.206-osx-x64/packs/Microsoft.NETCore.App.Runtime.Mono.android-arm64/8.0.11/runtimes/android-arm64/lib/net8.0/System.Private.Xml.dll".

That's bananas.

But wait, it's worse! Try that with a MAUI app -- which pulls in lots of NuGet packages, with assemblies in writable $HOME/.nuget -- and:

Moving file from "…/obj/Debug/net8.0-android/android-arm/aot-in/Xamarin.AndroidX.ExifInterface_trimmed.dll" to "$HOME/.nuget/packages/xamarin.androidx.exifinterface/1.3.6.2/lib/net6.0-android31.0/Xamarin.AndroidX.ExifInterface.dll".

There goes my NuGet cache!

@jonpryor jonpryor added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Dec 3, 2024
@jonathanpeppers
Copy link
Member

$(AndroidStripILAfterAOT) is definitely still in the realm of "experimental", should we put that on a doc somewhere?

@jpobst jpobst removed the needs-triage Issues that need to be assigned. label Dec 3, 2024
@jonpryor
Copy link
Member Author

jonpryor commented Dec 3, 2024

@jonathanpeppers wrote:

$(AndroidStripILAfterAOT) is definitely still in the realm of "experimental", should we put that on a doc somewhere?

I don't understand. Are you saying that we should document that if $(AndroidStripILAfterAOT)=true builds will hose your NuGet cache and thus corrupt all future builds? (That's quite the thing to only document.)

We should either fix this post haste, or remove support for $(AndroidStripILAfterAOT) (assuming that's the only thing that triggers the file overwrites).

@jonathanpeppers
Copy link
Member

I would suspect few are using $(AndroidStripILAfterAOT) (it's not a default setting), so they would have to discover that it exists.

The logic here is optional:

<ILStrip
Condition=" '$(AndroidStripILAfterAOT)' == 'true' "
TrimIndividualMethods="true"
Assemblies="@(_MonoAOTCompiledAssemblies)"
IntermediateOutputPath="$(IntermediateOutputPath)"
DisableParallelStripping="$(_DisableParallelAot)">
<Output TaskParameter="UpdatedAssemblies" ItemName="_ILStripUpdatedAssemblies" />
</ILStrip>
<Copy
Condition=" '$(AndroidStripILAfterAOT)' == 'true' and '%(_ILStripUpdatedAssemblies.ILStripped)' == 'true' and '%(_ILStripUpdatedAssemblies.UntrimmedAssemblyFilePath)' != '' "
SourceFiles="@(_ILStripUpdatedAssemblies)"
DestinationFiles="@(_ILStripUpdatedAssemblies->'%(UntrimmedAssemblyFilePath)')"
/>

It probably needs to be working against (yet another) folder with a copy of all assemblies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

No branches or pull requests

4 participants