godotengine / godot

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

Runtimes in the nuget package cannot be copied to the android library correctly. #60167

Open wenbingzhang opened 2 years ago

wenbingzhang commented 2 years ago

Godot version

mono 3.4.4.stable

System information

macos 11.6

Issue description

Runtimes in the nuget package cannot be copied to the android library correctly.

Steps to reproduce

Lua is not included in "libs" in "apk" exported from Android.

Minimal reproduction project

test.zip

wenbingzhang commented 2 years ago

Not only Android, but also Mac OS. Other platforms have not been tested yet.

raulsntos commented 2 years ago

The NLua NuGet package has a dependency on KeraLua which is the NuGet package that includes the liblua54.so file (the native library that KeraLua dlopens using DllImport).

Both NLua.dll and KeraLua.dll are included in the .mono/assemblies/Debug, the Mono export plugin manually copies these DLLs by iterating the game project's dependencies:

https://github.com/godotengine/godot/blob/d9991160545be05cebc9dea161eaf5b4d855e7db/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs#L145

https://github.com/godotengine/godot/blob/fe52458154c64fb1b741df4f7bd10106395f7cbd/modules/mono/editor/godotsharp_export.cpp#L108

This means the Mono export plugin only copies the referenced assemblies and not other files included in the NuGet packages (like native libraries). I assume if we were using dotnet publish this would just work and it would do the right thing, we are already moving to dotnet publish for exporting in Godot 4.0 (currently implemented in branch dotnet6) but, unfortunately, I don't think it'd be backported to 3.x.

The only workaround would be to copy the native libraries to a path where the game can find them which is not a simple task in an OS like Android. For an OS like Mac, having the .so files next to the binary should work.

Sounds like a duplicate of #22787

wenbingzhang commented 2 years ago

Android Using "gdnlib" can copy so to apk, and it can be used normally.

macos Mono' cannot call lib in' xxx.app/Contents/Frameworks'