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

[nativeaot] fix missing PreserveLists\*.xml files #9831

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonathanpeppers
Copy link
Member

A dotnet new maui project template fails to build with:

obj\Release\net10.0-android\android-arm64\android\src\mono\android\runtime\InputStreamAdapter.java:4: error: InputStreamAdapter is not abstract and does not override abstract method read() in InputStream
obj\Release\net10.0-android\android-arm64\android\src\mono\android\runtime\OutputStreamAdapter.java:4: error: OutputStreamAdapter is not abstract and does not override abstract method write(int) in OutputStream

I found I could also reproduce this issue with the BuildBasicApplicationAppCompat() MSBuild test.

After reviewing .binlog files, I found we weren't including PreserveLists\*.xml files at all in NativeAOT, as the Condition was false:

<_PreserveLists Include="$(MSBuildThisFileDirectory)..\PreserveLists\*.xml" />
<TrimmerRootDescriptor
    Condition=" '@(ResolvedFileToPublish->Count())' != '0' and '%(Filename)' != '' "
    Include="@(_PreserveLists)" />

9bc45b5 doesn't say why the Condition was added, but this was during early .NET 5 development. Some of this code may have been shared with Xamarin.Android back then.

We can simply remove the Condition to fix this, and the MSBuild test also passes.

@jonathanpeppers
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Context: 9bc45b5

A `dotnet new maui` project template fails to build with:

    obj\Release\net10.0-android\android-arm64\android\src\mono\android\runtime\InputStreamAdapter.java:4: error: InputStreamAdapter is not abstract and does not override abstract method read() in InputStream
    obj\Release\net10.0-android\android-arm64\android\src\mono\android\runtime\OutputStreamAdapter.java:4: error: OutputStreamAdapter is not abstract and does not override abstract method write(int) in OutputStream

I found I could also reproduce this issue with the
`BuildBasicApplicationAppCompat()` MSBuild test.

After reviewing `.binlog` files, I found we weren't including
`PreserveLists\*.xml` files *at all* in NativeAOT, as the `Condition`
was false:

    <_PreserveLists Include="$(MSBuildThisFileDirectory)..\PreserveLists\*.xml" />
    <TrimmerRootDescriptor
        Condition=" '@(ResolvedFileToPublish->Count())' != '0' and '%(Filename)' != '' "
        Include="@(_PreserveLists)" />

9bc45b5 doesn't say why the `Condition` was added, but this was
during early .NET 5 development. Some of this code may have been
shared with Xamarin.Android back then.

We can simply remove the `Condition` to fix this, and the MSBuild test
also passes.
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/NativeAOTPreserve branch from 5d45fad to 8b95494 Compare February 24, 2025 18:27
@jonathanpeppers jonathanpeppers marked this pull request as ready for review February 24, 2025 18:28
@jonathanpeppers
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant