-
Notifications
You must be signed in to change notification settings - Fork 810
chore: build & run SamplesApp.Skia.netcoremobile with NativeAOT on Android #21359
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
base: master
Are you sure you want to change the base?
chore: build & run SamplesApp.Skia.netcoremobile with NativeAOT on Android #21359
Conversation
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
There's going to be another SNAFU with this idea: dotnet/java-interop@90ac202 .NET 10 Previews 2 through 7 have a bug in .NET for Android wherein the app crashes when attempting to use boolean fields. As this PR builds
(I had forgotten encountering this crash, but the crash is why I fixed the java-interop bug two weeks ago…) Immediate-term, I'll build Longer-term, we either wait for the next September .NET 10 Preview release -- which should have the fix for this abort -- or we alter I'm partial to the latter, as it will speed things up. |
|
14dd13a
to
6b0649f
Compare
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
"Interestingly", the crash noted above? It's caused by making the app Debuggable! This patch: diff --git a/src/SamplesApp/SamplesApp.Skia.netcoremobile/Android/Main.Android.cs b/src/SamplesApp/SamplesApp.Skia.netcoremobile/Android/Main.Android.cs
index 79e647c76c..c3601f89f6 100644
--- a/src/SamplesApp/SamplesApp.Skia.netcoremobile/Android/Main.Android.cs
+++ b/src/SamplesApp/SamplesApp.Skia.netcoremobile/Android/Main.Android.cs
@@ -40,6 +40,7 @@ using Uno.UI;
namespace SamplesApp.Droid
{
[global::Android.App.ApplicationAttribute(
+ Debuggable = true,
Label = "@string/SamplesAppName",
Icon = "@mipmap/icon",
Banner = "@drawable/banner", breaks both Tests - Android Skia and the (currently nearly identical) Tests - Android+NativeAOT Skia. Offhand, I'm not sure why that would happen…but this does explain my confusion yesterday around why both Tests - Android Skia and Tests - Android+NativeAOT Skia would be crashing in the same way when running different binaries! TIL, and I'm still confuzzled. |
|
22ef026
to
d937156
Compare
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
The build 174741 found UI Test snapshots differences: Details
|
|
d937156
to
a2e3739
Compare
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
|
a2e3739
to
c5fce5a
Compare
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
|
c5fce5a
to
97e3c21
Compare
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
|
97e3c21
to
d1b7458
Compare
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
|
d1b7458
to
1f86e0e
Compare
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
…droid Context: #21256 / 52a6f3e Context: dotnet/android#10461 Context: dotnet/android#10457 Context: dotnet/android#10463 #21256 added support for building with .NET 10, and one of the new features in .NET 10 is that Android has (very!) preliminary preview support for [NativeAOT][0]. As building `SamplesApp.Skia.netcoremobile.csproj` with NativeAOT takes a significant amount of time and disk space, we've decided to introduce a new `Tests - Android+NativeAOT Skia` stage to build and run these unit tests within an Android+NativeAOT environment. To help reduce disk usage, after building the `.apk` we delete the `obj` directory. Update `android-run-skia-runtime-tests.sh` to always create the `$(build.sourcesdirectory)/build/uitests-failure-results` path before existing with an error, as failure to do so means that the `PublishBuildArtifacts@1` YAML task fails: ##[error]Publishing build artifacts failed with an error: Not found PathtoPublish: /agent/_work/1/s/build/uitests-failure-results which in turn means subsequent `DownloadBuildArtifacts@0` / **Download previous test runs failed tests** steps *also* always fail: ##[error]Artifact uitests-android-nativeaot-failure-results not found for build 174635. Please ensure you have published artifacts in any previous phases of the current build. Update `ApplicationData.GetRoamingFolder()` to explicitly create `Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)`. (Apparently this isn't created by default under NativeAOT?) This avoids a startup assertion: I NativeAotFromAndroid: App failed to initialize: System.IO.DirectoryNotFoundException: IO_PathNotFound_Path, /data/user/0/uno.platform.samplesapp.skia/files/.config/b63c4306-f361-42d0-bc1d-5be385a95c78.txt I NativeAotFromAndroid: at System.IO.FileSystem.DeleteFile(String) + 0xe7 I NativeAotFromAndroid: at SamplesApp.App.<AssertApplicationData>g__AssertCanCreateFile|32_3(StorageFolder) + 0x10c I NativeAotFromAndroid: at SamplesApp.App.AssertApplicationData() + 0xa5 I NativeAotFromAndroid: at SamplesApp.App..ctor() + 0x2a3 I NativeAotFromAndroid: at SamplesApp.Droid.Application.<>c.<.ctor>b__0_0() + 0x18 I NativeAotFromAndroid: at Microsoft.UI.Xaml.NativeApplication.<OnActivityStarted>b__7_0() + 0x12 I NativeAotFromAndroid: at Uno.UI.Runtime.Skia.Android.AndroidHost.<Run>g__CreateApp|2_10(ApplicationInitializationCallbackParams _) + 0xf I NativeAotFromAndroid: at Microsoft.UI.Xaml.Application.StartPartial(ApplicationInitializationCallback callback) + 0xb5 I NativeAotFromAndroid: at Uno.UI.Runtime.Skia.Android.AndroidHost.Run() + 0x306 Enable NativeAOT builds by updating `SamplesApp.Skia.netcoremobile.csproj` to set the [`$(PublishAot)`][1] property to the `$(SkiaPublishAot)` MSBuild property. This allows us to build a single project for NativeAOT -- `SamplesApp.Skia.netcoremobile.csproj` -- *without* trying to build every referenced project for NativeAOT, which is what happens if you instead try `dotnet publish -p:PublishAot=true …`: % dotnet build -c Release -p:PublishAot=true src/SamplesApp/SamplesApp.Skia.netcoremobile/SamplesApp.Skia.netcoremobile.csproj -bl … …/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(121,5): error NETSDK1207: Ahead-of-time compilation is not supported for the target framework. % dotnet publish src/SamplesApp/SamplesApp.Skia.netcoremobile/SamplesApp.Skia.netcoremobile.csproj \ -c Release -r android-x64 -f net10.0-android -p:UnoTargetFrameworkOverride=net10.0-android -p:SkiaPublishAot=true -bl # succeeds… after 15 minutes… This also requires updating `$(NoWarn)` to ignore the hundreds of IL trimmer warnings. We're just trying to see where things stand for now. Additionally, we need to publish with `-r android-x64` in order to avoid the build error: …/Microsoft.NETCore.Native.Publish.targets(92,5): error MSB3030: Could not copy the file "bin/Release/net10.0-android/native/SamplesApp.so" because it was not found. Because it's `bin/Release/net10.0-android/android-{arm64,x64}/native/SamplesApp.so`! Oddly, using `-r android-x64` still results in *both* ABIs being included, which appears to be a unoplatform/uno "bug": % unzip -l src/SamplesApp/SamplesApp.Skia.netcoremobile/bin/Release/net10.0-android/android-x64/publish/uno.platform.samplesapp.skia-Signed.apk | grep SamplesApp.so 763563120 08-28-2025 19:47 lib/x86_64/libSamplesApp.so 757982224 08-28-2025 19:48 lib/arm64-v8a/libSamplesApp.so The need for `-r android-x64` may be related to dotnet/android#10457. Finally, .NET Crypto support isn't propertly initialized in Android+NativeAOT apps in .NET 10 RC1; see dotnet/android#10463. This may be fixed in dotnet/android#10461, but in the meantime we can manually call `AndroidCryptoNative_InitLibraryOnLoad()` so that methods such as `SHA1.Create()` won't throw. Note: Do *not* make Release-config apps [Debuggable][2] under .NET 10 Preview 7 or earlier; you will run into [dotnet/java-interop@90ac202e][3]. [0]: https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/ [1]: https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/?tabs=windows%2Cnet8#publish-native-aot-using-the-cli [2]: https://developer.android.com/guide/topics/manifest/application-element#debug [3]: dotnet/java-interop@90ac202
1f86e0e
to
ae41318
Compare
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21359/wasm-skia-net9/index.html |
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21359/docs/index.html |
|
Context: #21256
#21256 added support for building with .NET 10, and one of the new features in .NET 10 is that Android has (very!) preliminary preview support for NativeAOT.
As building
SamplesApp.Skia.netcoremobile.csproj
with NativeAOT takes a significant amount of time, we've decided to introduce a new stage to build and run these new unit tests.Initially, though, this PR won't build for NativeAOT. This is to ensure that the various build artifacts are built in the expected locations. Once the non-NativeAOT build works, we'll enable it.
Update
Main.Android.cs
so thatDebuggable
is always true. NativeAOT can only be used with Release configuration builds, so this is necessary to "poking around" the installation directory.Update
DeviceTargetHelper.cs
: the current Android+NativeAOT support is built atop Linux support, to the extent thatOperatingSystem.IsLinux()
is true! Extend the platform detection logic so that the app can startup, avoiding an assertion:Update
ApplicationData.GetRoamingFolder()
to explicitly createEnvironment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
. (Apparently this isn't created by default under NativeAOT?) This avoids a startup assertion:TODO:
$(SkiaPublishAot)
MSBuild property withinSamplesApp.Skia.netcoremobile.csproj
.GitHub Issue: closes #
PR Type:
What is the current behavior? 🤔
What is the new behavior? 🚀
PR Checklist ✅
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Run
results.Other information ℹ️