godotengine / godot

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

Android Export Crashes on Startup with .NET 9 #98107

Open atlasapplications opened 2 days ago

atlasapplications commented 2 days ago

Tested versions

System information

Built on Windows 11 Tested on Google Pixel 8 (Android 14)

Issue description

Although the editor appears to successfully export the Android apk using .NET 9, when launched, it crashes on startup. Using the Logcat I'm able to retrieve this error:

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xb40000706385f85 in tid 11785 (VkThread), pid 11745 (m.example.test1)
Cmdline: com.example.test1
pid: 11745, tid: 11785, name: VkThread  >>> com.example.test1 <<<
NOTE: Function names and BuildId information is missing for some frames due
NOTE: to unreadable libraries. For unwinds of apps, only shared libraries
NOTE: found under the lib/ directory are readable.
NOTE: Unreadable libraries:
NOTE:   /data/data/com.example.test1/cache/data_Setup Project_android_arm64/libcoreclr.so
NOTE:   /data/data/com.example.test1/cache/data_Setup Project_android_arm64/libhostfxr.so
NOTE:   /data/data/com.example.test1/cache/data_Setup Project_android_arm64/libhostpolicy.so
...

It appears that those are native libraries that are not being loaded. Looks similar to #65863 which points in the direction that .NET is not actually being included in the export. Seems to work fine in the editor and when exported to Windows. Also doesn't work on iOS which might be the same issue.

Steps to reproduce

  1. Create project and set target framework to .NET 9.
  2. Export to Android.
  3. Launch the application.

Minimal reproduction project (MRP)

android_export_crash.zip

raulsntos commented 1 day ago

I'm unable to reproduce with Godot v4.3.stable.mono.official [77dcf97d8] using the default .csproj created by Godot (only changing the TFM to net9.0):

<Project Sdk="Godot.NET.Sdk/4.3.0">
  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>
</Project>

Looks like Android is complaining about some native .NET libraries. I don't know what the error means by "unreadable libraries". Is it that it doesn't have enough permissions to read them? Is it that the files are missing? Or could it be that those native libraries were built for a different target architecture?

You can also try to clear that cache directory (/data/data/com.example.test1/cache/). It may be that those files are outdated from a previous export, but I think this is unlikely because the hash of those files would be different.

Android exports also changed quite a bit in 4.4, we know put those native libraries in the /lib directory of the APK instead of /assets, so it may have solved the issue. Can you try exporting with 4.4.dev3 and see if it makes a difference?

Also doesn't work on iOS which might be the same issue.

iOS exports works very differently from other platforms and uses the NativeAOT runtime, so it's likely a different issue.

atlasapplications commented 1 day ago

I uploaded an MRP just in case our settings are different.

You can also try to clear that cache directory (/data/data/com.example.test1/cache/). It may be that those files are outdated from a previous export, but I think this is unlikely because the hash of those files would be different.

I cleared that as recommended and tried a different package name so it installed into a different directory. But the same error showed.

Can you try exporting with 4.4.dev3 and see if it makes a difference?

Yep! I'll try that next.

raulsntos commented 1 day ago

I'm still unable to reproduce with your MRP, it may be a difference on the Android device/emulator. Can you share the system information? (i.e.: Android OS version)

atlasapplications commented 1 day ago

Can you share the system information? (i.e.: Android OS version)

Updated!

I tested on 4.4.dev3 and this did indeed make a difference. The crash did not occur so it seems the issue could have been fixed.