Skip to content

Publish an android-x64 .NET runtime package - #3818

Merged
csukuangfj merged 1 commit into
k2-fsa:masterfrom
kfrancis:dotnet-android-x64-rid
Jul 29, 2026
Merged

csukuangfj merged 1 commit into
k2-fsa:masterfrom
kfrancis:dotnet-android-x64-rid

Conversation

@kfrancis

@kfrancis kfrancis commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3817

Problem

The .NET distribution ships per-RID native packages plus the org.k2fsa.sherpa.onnx meta-package, but there is no android-x64 runtime package. The .NET RID graph falls back android-x64 → linux-bionic-x64 → linux-x64, so any .NET for Android or MAUI app building for the x86_64 ABI silently resolves the manylinux glibc binaries from org.k2fsa.sherpa.onnx.runtime.linux-x64 and packs them into lib/x86_64/ of the APK/AAB. Those binaries cannot load under bionic at all, and additionally fail Google Play's 16 KB page size requirement (which blocks app updates from 31 May 2026).

android-x64 is the only affected ABI: android-arm64 already has a more specific package that wins RID resolution, and the 32-bit Android RIDs have no linux-arm/linux-x86 packages to fall back to, so they fail loudly at restore/build time instead of packing broken binaries.

Evidence

Broken binaries currently resolved via fallback — org.k2fsa.sherpa.onnx.runtime.linux-x64 1.13.4, runtimes/linux-x64/native/:

libsherpa-onnx-c-api.so
  PT_LOAD p_align: 0x1000
  NEEDED: libpthread.so.0, libonnxruntime.so, libdl.so.2, libm.so.6,
          libstdc++.so.6, libgcc_s.so.1, libc.so.6, ld-linux-x86-64.so.2
libonnxruntime.so
  PT_LOAD p_align: 0x1000
  NEEDED: libdl.so.2, librt.so.1, libpthread.so.0, libstdc++.so.6,
          libm.so.6, libgcc_s.so.1, libc.so.6, ld-linux-x86-64.so.2

4 KB p_align fails the 16 KB page size requirement; the glibc/ld-linux-x86-64.so.2 dependencies cannot be satisfied by bionic.

Correct binaries already published — sherpa-onnx-v1.13.4-android.tar.bz2, jniLibs/x86_64/:

libsherpa-onnx-c-api.so
  PT_LOAD p_align: 0x4000
  NEEDED: libandroid.so, liblog.so, libonnxruntime.so, libm.so, libdl.so, libc.so
libonnxruntime.so
  PT_LOAD p_align: 0x4000
  NEEDED: libdl.so, liblog.so, libm.so, libc.so

16 KB aligned, bionic-only dependencies. This is the same release asset the android-arm64 package is already built from — the fix is packaging only; nothing is recompiled.

Changes

  • scripts/dotnet/run.sh — add android-x64 to RIDS; restructure the Android download block so the single sherpa-onnx-v<VERSION>-android.tar.bz2 is downloaded at most once and feeds both android-arm64 (from jniLibs/arm64-v8a/) and android-x64 (from jniLibs/x86_64/), keeping the per-RID idempotency guards. Renamed android_arm64_tarball* vars to android_tarball* since the tarball was never arm64-specific.
  • scripts/dotnet/generate.py — add process_android(s, "x64"); process_android was already RID-parameterized.
  • scripts/dotnet/sherpa-onnx.csproj.in — add android-x64 to <RuntimeIdentifiers> and a PackageReference to org.k2fsa.sherpa.onnx.runtime.android-x64 in the meta-package.
  • scripts/dotnet/.gitignore — ignore the generated android-x64/ staging directory, matching the other RID directories.

Verified locally: bash -n run.sh and ast.parse(generate.py) pass; rendering sherpa-onnx.csproj.runtime.in for android-x64 produces <RuntimeIdentifier>android-x64</RuntimeIdentifier>, <PackageId>org.k2fsa.sherpa.onnx.runtime.android-x64</PackageId>, and PackagePath runtimes/android-x64/native/%(Filename)%(Extension); the meta template renders the new RID and package reference.

No changes to .github/workflows/ were needed: dot-net.yaml and test-dot-net.yaml invoke scripts/dotnet/run.sh and push org.k2fsa.sherpa.onnx.*.nupkg with a wildcard — they don't enumerate RIDs. All other android-arm64 grep hits are NDK build scripts (build-android-arm64-v8a.sh), APK scripts, or Flutter packaging, which are unrelated to .NET RIDs.

Notes

  • This takes effect for consumers only after a maintainer with NuGet publish credentials runs scripts/dotnet/run.sh (via the dot-net.yaml release workflow) for a release; merging alone publishes nothing.
  • android-arm / android-x86 (32-bit) are deliberately not added. They are not silently broken today — with no linux-arm/linux-x86 fallback packages, resolution fails visibly instead of packing wrong binaries. The tarball does contain armeabi-v7a/ and x86/ libraries, so the same pattern could add them later if anyone still targets 32-bit Android; kept out of scope here to keep the review focused.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added support for Android x64 runtime distribution alongside Android arm64.
    • Android x64 native libraries are now included in generated .NET runtime packages.
  • Bug Fixes

    • Improved Android runtime packaging to reliably acquire and include required native libraries for both supported architectures.
  • Chores

    • Updated runtime configuration and build automation to recognize the Android x64 target.

Without an android-x64 runtime package, .NET RID fallback resolves
android-x64 -> linux-bionic-x64 -> linux-x64, so .NET for Android and
MAUI apps building for the x86_64 ABI pack the manylinux glibc
libsherpa-onnx-c-api.so and libonnxruntime.so into lib/x86_64/. Those
are 4 KB aligned (failing Google Play's 16 KB page size requirement)
and link against ld-linux-x86-64.so.2, so they cannot load under bionic.

The correct binaries already ship in sherpa-onnx-v<VERSION>-android.tar.bz2
under jniLibs/x86_64/. Source the new package from there, exactly as
android-arm64 is sourced from jniLibs/arm64-v8a/.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 28, 2026
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The .NET Android packaging pipeline now supports the android-x64 runtime by generating its project, acquiring its native libraries, registering its runtime identifier, and including its NuGet package reference.

Changes

Android x64 packaging

Layer / File(s) Summary
Runtime generation and package wiring
scripts/dotnet/.gitignore, scripts/dotnet/generate.py, scripts/dotnet/sherpa-onnx.csproj.in
The generator creates the Android x64 runtime project, the project template registers android-x64 and its package, and Git ignores the generated target directory.
Android native-library acquisition
scripts/dotnet/run.sh
The build script handles arm64 and x64 Android libraries from one shared tarball and includes both runtime identifiers in its build and pack loops.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BuildScript
  participant AndroidArchive
  participant RuntimeDirectories
  participant NuGetProject
  BuildScript->>AndroidArchive: Download and extract Android libraries when needed
  AndroidArchive->>RuntimeDirectories: Copy arm64 and x64 native libraries
  BuildScript->>NuGetProject: Build and package configured runtime identifiers
Loading

Possibly related issues

  • Issue 3817: Directly covers the Android x64 .NET RID packaging fix implemented here.

Possibly related PRs

  • k2-fsa/sherpa-onnx#3485: Introduced the Android .NET packaging pipeline that this change extends with android-x64.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding an android-x64 .NET runtime package.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/dotnet/run.sh`:
- Around line 91-110: Update the Android staging guards in the
download/extraction block to verify both required files, libonnxruntime.so and
libsherpa-onnx-c-api.so, for each android-arm64 and android-x64 directory.
Trigger extraction and copying whenever either library is missing, while
preserving the existing per-architecture copy behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aa91e916-33c1-42ee-89e3-650a1c3557fa

📥 Commits

Reviewing files that changed from the base of the PR and between d1fedc1 and 52f4da6.

📒 Files selected for processing (4)
  • scripts/dotnet/.gitignore
  • scripts/dotnet/generate.py
  • scripts/dotnet/run.sh
  • scripts/dotnet/sherpa-onnx.csproj.in

Comment thread scripts/dotnet/run.sh
@kfrancis

Copy link
Copy Markdown
Contributor Author

Thanks — keeping the single-file guard as-is, for consistency with the rest of the script. All seven other download blocks in run.sh use the same one-sentinel idiom (check a single library, e.g. libsherpa-onnx-c-api.so), and this PR deliberately preserves the guard that the original android-arm64 block already had.

A partially-staged directory can't occur through normal execution: both libraries are copied by a single cp invocation, and the script runs under set -e, so a failed copy aborts the run before leaving partial state. CI starts from a fresh /tmp each run, so the only way to hit the missing-libonnxruntime.so case is manually deleting one file from a local cache — and rm -rf $src_dir/android-* recovers that.

Happy to switch to the both-files check if the maintainers prefer it, but I'd rather not diverge from the established style of the script in this PR.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a .NET/NuGet packaging gap by adding an android-x64 runtime package so RID resolution no longer falls back to linux-x64 (glibc / 4 KB-aligned binaries) for Android x86_64 consumers. It extends the existing .NET packaging scripts/templates to stage and pack the already-published Android release tarball’s jniLibs/x86_64 binaries into a proper runtimes/android-x64/native/ NuGet runtime package, and wires that package into the meta-package.

Changes:

  • Add android-x64 to the .NET meta-package <RuntimeIdentifiers> and its runtime-package dependency list.
  • Extend the dotnet packaging scripts to stage jniLibs/x86_64 from the Android release tarball and generate/build an android-x64 runtime .nupkg.
  • Ignore the generated scripts/dotnet/android-x64/ staging directory in the dotnet scripts’ .gitignore.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
scripts/dotnet/run.sh Adds android-x64 RID and reworks Android tarball staging to populate both android-arm64 and android-x64 from one download/extract.
scripts/dotnet/generate.py Generates the android-x64 runtime project alongside the existing android-arm64 one.
scripts/dotnet/sherpa-onnx.csproj.in Adds android-x64 to the meta-package RIDs and references org.k2fsa.sherpa.onnx.runtime.android-x64.
scripts/dotnet/.gitignore Ignores the new android-x64 staging directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@csukuangfj csukuangfj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] .NET package: no android-x64 RID, so RID fallback ships the glibc linux-x64 .so (4 KB aligned) into Android app bundles

3 participants