Skip to content

[nativeaot] support multi-RID builds #9826

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

Merged
merged 1 commit into from
Feb 24, 2025
Merged

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Feb 21, 2025

Context: https://github.com/dotnet/sdk/blob/68bf4cbabc023e5c2752ee4d5ce7e4a40929e748/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets#L227-L229

The only blocker for supporting $(RuntimeIdentifiers)=android-arm64;android-x64 is the error message:

error NETSDK1191: A runtime identifier for the property 'PublishAot' couldn't be inferred. Specify a rid explicitly.

We can set $(AllowPublishAotWithoutRuntimeIdentifier) by default, as this is not an error we'd ever want to show on Android.

After this change I can see the MSBuild terminal logger shows the two RIDs building in parallel:

MyApp     IlcCompile (8.7s)
MyApp     IlcCompile (8.6s)

And then the resulting .apk has both lib/arm64-v8a and lib/x86_64.

I also updated some of our MSBuild test infrastructure to make it easier to parameterize more MSBuild tests for $(PublishAot)=true in the future.

We'll likely want to do tests like:

[Test]
public void SomeTest ([Values (true, false)] bool publishAot)
{
    var proj = new XamarinAndroidApplicationProject ();
    if (publishAot) {
        proj.SetPublishAot (true, AndroidNdkPath);
    }
    //...
}

Context: https://github.com/dotnet/sdk/blob/68bf4cbabc023e5c2752ee4d5ce7e4a40929e748/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets#L227-L229

The only blocker for supporting `$(RuntimeIdentifiers)=android-arm64;android-x64`
is the error message:

    error NETSDK1191: A runtime identifier for the property 'PublishAot' couldn't be inferred. Specify a rid explicitly.

We can set `$(AllowPublishAotWithoutRuntimeIdentifier)` by default, as
this is not an error we'd ever want to show on Android.

After this change I can see the MSBuild terminal logger shows the two
RIDs building in parallel:

    NativeAOT     IlcCompile (8.7s)
    NativeAOT     IlcCompile (8.6s)

And then the resulting `.apk` has both `lib/arm64-v8a` and `lib/x86_64`.

I also updated some of our MSBuild test infrastructure to make it
easier to parameterize more MSBuild tests for `$(PublishAot)=true` in
the future.

We'll likely want to do tests like:

    [Test]
    public void SomeTest ([Values (true, false)] bool publishAot)
    {
        var proj = new XamarinAndroidApplicationProject ();
        if (publishAot) {
            proj.SetPublishAot (true, AndroidNdkPath);
        }
        //...
    }
@jonathanpeppers jonathanpeppers marked this pull request as ready for review February 22, 2025 17:06
@jonpryor jonpryor merged commit b2c73ff into main Feb 24, 2025
58 checks passed
@jonpryor jonpryor deleted the dev/peppers/AllowPublishAot branch February 24, 2025 18:20
@Delsin-Yu
Copy link

Does this mean we can now target android-arm64;android-x64 when publishing using NAOT and have proper JNI support (e.g. System.Cryptography)?

@jonathanpeppers
Copy link
Member Author

NativeAOT is still a prototype, the next several .NET 10 previews will likely emit a warning similar to:

warning XA1040: The NativeAOT runtime on Android is an experimental feature and not yet suitable for production use. File issues at: https://github.com/dotnet/android/issues

It will be a good time to test and file issues though, thanks!

@Delsin-Yu
Copy link

Thank you for elaborating! Just to avoid unnecessary checkups, is it available in dotnet 10 Preview 1?

@filipnavara
Copy link
Member

is it available in dotnet 10 Preview 1?

No.

have proper JNI support (e.g. System.Cryptography)?

JNI support and System.Cryptography are two totally independent things.

System.Security.Cryptography depends on producing NativeAOT runtime packs targeting android-[arm64/x64/...] instead of linux-bionix-[...]. That's not done yet.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants