godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.1k stars 21.18k forks source link

net8.0-android failed to build, assembly not found #97613

Open symful opened 1 month ago

symful commented 1 month ago

Tested versions

System information

Godot v4.3.stable.mono - Manjaro Linux #1 SMP PREEMPT_DYNAMIC Wed Aug 7 16:19:28 UTC 2024 - Wayland - GLES3 (Compatibility) - AMD Radeon Vega 3 Graphics (radeonsi, raven2, LLVM 18.1.8, DRM 3.57, 6.9.12-3-MANJARO) - AMD Ryzen 3 3250U with Radeon Graphics (4 Threads)

Issue description

I am forced to use net8.0-android because I need to have SkiaSharp.NativeAssets.Android for APK. When building APK, it emits this: Screenshot from 2024-09-29 15-29-35

Though, if I use net8.0 it will be built. But libSkiaSharp dll won't be found (during using the application) [messages from logcat]

09-29 13:49:30.972  9234  9354 E godot   : USER ERROR: System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
09-29 13:49:30.972  9234  9354 E godot   :  ---> System.DllNotFoundException: libSkiaSharp
09-29 13:49:30.972  9234  9354 E godot   :    at SkiaSharp.SKImageInfo..cctor()
09-29 13:49:30.972  9234  9354 E godot   :    --- End of inner exception stack trace ---
09-29 13:49:30.972  9234  9354 E godot   :    at SkiaSharp.Views.Godot.SKControl._Draw()
09-29 13:49:30.972  9234  9354 E godot   :    at Godot.CanvasItem.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret)
09-29 13:49:30.972  9234  9354 E godot   :    at Godot.Control.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret)
09-29 13:49:30.972  9234  9354 E godot   :    at SkiaSharp.Views.Godot.SKControl.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret)
09-29 13:49:30.972  9234  9354 E godot   :    at Godot.Bridge.CSharpInstanceBridge.Call(IntPtr godotObjectGCHandle, godot_string_name* method, godot_variant** args, Int32 argCount, godot_variant_call_error* refCallError, godot_variant* ret)
09-29 13:49:30.972  9234  9354 E godot   :    at: void Godot.NativeInterop.ExceptionUtils.LogException(System.Exception) (:0)

I expected from one of these, I can use SkiaSharp on Android.

Steps to reproduce

  1. Clone recursively: GitHub
  2. Open the Godot project in the scene/ folder
  3. Export Android

You may change the TargetFramework in the folder to net8.0, compile it, then run in your phone to test it out for the second case I mentioned above.

Minimal reproduction project (MRP)

https://github.com/symful/kaolin.flow-godot-skiasharp (not so minimal, but I don't have time to make one)

raulsntos commented 1 month ago

The net8.0-android TFM is not supported by Godot. We use dotnet publish to export .NET projects, but Android TFMs like net8.0-android don't seem to work with that.

As far as I know, in Android projects dotnet publish should copy the result of dotnet build to $(PublishDir) but that doesn't seem to work. As you can see in the screenshot you shared, the Scene.dll file is not in the expected output directory.

But to be honest, even if the output files were copied to the expected directory, I'm not sure that'd be enough to make it work with how we're hosting the .NET runtime. I imagine net8.0-android is designed to work with the dotnet/android host, which contains all the necessary pieces to make that work.