Dotnet Android targeting - #3485
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR adds Android arm64 runtime package support to the sherpa-onnx .NET ecosystem. It introduces Android-specific build generation logic, updates project configurations to target Android, and refactors the build script to handle multiple runtime identifiers dynamically while fetching Android native libraries. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Thank you for your contribution!
Please use the following file sherpa-onnx-v1.12.35-android.tar.bz2 You can find the required .so files for Android inside it. Users have successfully used Rust with Android via Tauri. Note that you only need to copy two |
|
Please also update and sherpa-onnx/scripts/dotnet/sherpa-onnx.csproj.in Lines 50 to 58 in 07c119a |
There was a problem hiding this comment.
Code Review
This pull request introduces support for the android-arm64 platform in the .NET build scripts. Key changes include updating the gitignore, adding a process_android function to the generation script, and refactoring run.sh to use an array and a loop for building various Runtime Identifiers (RIDs). A syntax error was identified in the new bash loop in run.sh that requires a semicolon or newline before the 'do' keyword.
|
by the way, make sure you know the changes you are making. Here is what chatgpt tells me that should be changed for the csproj file. Please test the changes locally. |
<Project Sdk="Microsoft.NET.Sdk">
<!-- =========================
General Properties
========================= -->
<PropertyGroup>
<TargetFrameworks>
net8.0;
net7.0;
net6.0;
netstandard2.0;
net8.0-android
</TargetFrameworks>
<OutputType>Library</OutputType>
<LangVersion>10.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>sherpa-onnx</AssemblyName>
<Version>{{ version }}</Version>
<!-- NuGet Metadata -->
<PackageId>org.k2fsa.sherpa.onnx</PackageId>
<Title>sherpa-onnx v{{ version }}</Title>
<Authors>The Next-gen Kaldi development team</Authors>
<Company>Xiaomi Corporation</Company>
<Description>
sherpa-onnx is an open-source real-time speech recognition toolkit.
It supports offline streaming recognition across multiple platforms.
</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/k2-fsa/sherpa-onnx</PackageProjectUrl>
<RepositoryUrl>https://github.com/k2-fsa/sherpa-onnx</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>
speech recognition voice audio stt asr speech-to-text AI offline
</PackageTags>
<!-- Signing -->
<SignAssembly>false</SignAssembly>
<PublicSign>false</PublicSign>
<DelaySign>false</DelaySign>
</PropertyGroup>
<!-- =========================
Restore Sources
========================= -->
<PropertyGroup>
<RestoreSources>
{{ packages_dir }};
$(RestoreSources);
https://api.nuget.org/v3/index.json
</RestoreSources>
</PropertyGroup>
<!-- =========================
Package Content
========================= -->
<ItemGroup>
<None Include="../README.md" Pack="true" PackagePath="/" />
</ItemGroup>
<!-- =========================
Platform-specific runtimes
========================= -->
<!-- Windows -->
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x64" Version="{{ version }}" />
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x86" Version="{{ version }}" />
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-arm64" Version="{{ version }}" />
</ItemGroup>
<!-- Linux -->
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.linux-x64" Version="{{ version }}" />
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.linux-arm64" Version="{{ version }}" />
</ItemGroup>
<!-- macOS -->
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-x64" Version="{{ version }}" />
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-arm64" Version="{{ version }}" />
</ItemGroup>
<!-- Android -->
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.android-arm64" Version="{{ version }}" />
</ItemGroup>
</Project>Here is the suggestion from ChatGPT. You can test it. |
|
https://github.com/k2-fsa/sherpa-onnx/actions/runs/24126389428/workflow Here is the CI in case you want to test it locally. |
|
No worries, I've already been testing it locally by adding the built .nupkgs as a local package source for my application. It definitely no longer struggles with loading the DLL now.
I'm pretty sure ChatGPT is wrong here; the OS-specific TFM is needed if the library is using platform specific APIs, but this only refers to C# APIs, not native runtime libraries. It builds and runs fine for me without the additional net8.0-android TFM. The conditional ItemGroups are also wrong, because MSBuild::IsOSPlatform checks the OS of the build host. So with the changes proposed by ChatGPT the CI would end up publishing a NuGet package that exclusively depends on the Linux runtime packages, and would therefore break on any other platform. I suppose adding OS-specific TFMs for every supported platform and then making the runtime packages conditional on that could make sense, but I'm pretty sure that depending on how the final application is published (portable vs for a specific target runtime) , those runtimes are already stripped out anyway so it wouldn't really do much. For example, looking inside the produced APK I only see the Android runtime libraries anyway. While I'm at it though, I could add the recently released net10.0 to TargetFrameworks if that's okay. |
|
Yes, please add net10.0 |
Done! Is there a defined order in which things are run in CI? Or is it all parallel? If a release is made, the Android native libraries need to be done building before the dotnet packages for the same version.
Also done. |
|
The CI is triggered manually after all deps are built. Thanks! Will release this week. Probably tomorrow. |
|
Wonderful! I've removed the draft status as well. |
csukuangfj
left a comment
There was a problem hiding this comment.
Thank you again for your contribution!
|
New NuGet packages released. Please re-check. https://www.nuget.org/packages/org.k2fsa.sherpa.onnx.runtime.android-arm64/ |
|
Seems to work as before! On to actually implementing and testing now :D Thanks for the quick release! |
Fixes #3483 and probably also #1241
This is marked WIP because I am currently just grabbing the sherpa-onnx-c-api from a local android build, because there is no Android specific wheel I can just grab off of Huggingface. Not sure if Android wheels are even a thing? I don't know much about wheels in general.
Anyway, I manually built the necessary libraries with this command:
SHERPA_ONNX_ENABLE_C_API=ON ./build-android-arm64-v8a.sh. But I did not look at how to integrate this with CI yet because I wasn't sure what the preferred way forward actually is. Thoughts?Summary by CodeRabbit