godotengine / godot

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

Mono 3.2 Game on Android crash with custom export template #36692

Closed harmonicsolutions closed 4 years ago

harmonicsolutions commented 4 years ago

Godot version: Godot Mono 3.2 Stable

OS/device including version: macOS high sierra

Issue description: To reduce APK size of the game, I created android custom template on Ubuntu 18.04. I could not create it on Mac and I already raised bug for it: https://github.com/godotengine/godot/issues/36508

Steps to reproduce: 1 - Open Godot Mono 3.2 Stable on Mac 2 - Use Android export template which is created in Ubuntu 18.04 3 - Export the game for Android (Debug or Release) 4 - Use adb install to install game into the phone.

When i open the game, It crashes.

Logcat output with Debug apk:

2020-03-01 01:37:01.314 652-1260/system_process I/ActivityManager: Start proc 21558:game.package/u0a128 for activity game.package/com.godot.game.GodotApp
2020-03-01 01:37:02.406 21558-21598/game.package I/godot: Loading Android module: org/godotengine/godot/Firebase
2020-03-01 01:37:02.426 21558-21598/game.package I/godot: Loading Android module: org/godotengine/godot/SQLBridge
2020-03-01 01:37:02.441 21558-21598/game.package D/godot: SQLBridge:Initialized
2020-03-01 01:37:02.441 21558-21598/game.package I/godot: Loading Android module: org/godotengine/godot/GodotPaymentV3
2020-03-01 01:37:02.452 21558-21598/game.package I/godot: Loading Android module: org/godotengine/godot/GodotShare
2020-03-01 01:37:02.527 21558-21598/game.package I/godot: Godot Engine v3.2.stable.mono.custom_build.4e7d75ccd - https://godotengine.org
2020-03-01 01:37:02.551 21558-21598/game.package I/godot: OpenGL ES 2.0 Renderer: Adreno (TM) 330
2020-03-01 01:37:02.652 21558-21598/game.package I/godot:  
2020-03-01 01:37:02.919 21558-21598/game.package E/godot: **ERROR**: Mono: Core API hash mismatch.
2020-03-01 01:37:02.920 21558-21598/game.package E/godot:    At: modules/mono/mono_gd/gd_mono.cpp:465:_init_godot_api_hashes() - Mono: Core API hash mismatch.
2020-03-01 01:37:02.922 21558-21598/game.package I/godot: Mono: Logfile is: /data/data/game.package/files/mono/mono_logs/2020_03_01 01.37.02 (21558).txt
2020-03-01 01:37:03.063 21558-21598/game.package E/godot: **ERROR**: The assembly 'GodotSharp' is out of sync.
2020-03-01 01:37:03.063 21558-21598/game.package E/godot:    At: modules/mono/mono_gd/gd_mono.cpp:926:_load_api_assemblies() - The assembly 'GodotSharp' is out of sync.
2020-03-01 01:37:03.063 21558-21598/game.package E/godot: **ERROR**: FATAL: Method failed.
2020-03-01 01:37:03.063 21558-21598/game.package E/godot:    At: modules/mono/mono_gd/gd_mono.cpp:937:_load_api_assemblies() - FATAL: Method failed.
2020-03-01 01:37:03.135 652-2189/system_process W/InputDispatcher: channel '468d499 game.package/com.godot.game.GodotApp (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
2020-03-01 01:37:03.135 652-2189/system_process E/InputDispatcher: channel '468d499 game.package/com.godot.game.GodotApp (server)' ~ Channel is unrecoverably broken and will be disposed!
2020-03-01 01:37:03.139 652-4407/system_process I/WindowManager: WIN DEATH: Window{468d499 u0 game.package/com.godot.game.GodotApp}
2020-03-01 01:37:03.139 652-4407/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel '468d499 game.package/com.godot.game.GodotApp (server)'
2020-03-01 01:37:03.140 652-13070/system_process W/ActivityManager: Force removing ActivityRecord{8230fac u0 game.package/com.godot.game.GodotApp t192}: app died, no saved state
2020-03-01 01:37:03.223 652-1257/system_process I/ActivityManager: Displayed game.package/com.godot.game.GodotApp: +1s930ms

Logcat output with Release apk:

2020-03-01 01:14:45.356 19881-19922/? I/godot: Loading Android module: org/godotengine/godot/Firebase
2020-03-01 01:14:45.366 19881-19922/? I/godot: Loading Android module: org/godotengine/godot/SQLBridge
2020-03-01 01:14:45.367 19881-19922/? D/godot: SQLBridge:Initialized
2020-03-01 01:14:45.367 19881-19922/? I/godot: Loading Android module: org/godotengine/godot/GodotPaymentV3
2020-03-01 01:14:45.369 19881-19922/? I/godot: Loading Android module: org/godotengine/godot/GodotShare
2020-03-01 01:14:45.422 19881-19922/? I/godot: Godot Engine v3.2.stable.mono.custom_build.4e7d75ccd - https://godotengine.org
2020-03-01 01:14:45.435 19881-19922/? I/godot: OpenGL ES 2.0 Renderer: Adreno (TM) 330
2020-03-01 01:14:45.552 19881-19922/? I/godot:  
2020-03-01 01:14:45.734 19881-19922/? I/godot: Mono: Logfile is: /data/data/game.package/files/mono/mono_logs/2020_03_01 01.14.45 (19881).txt
2020-03-01 01:14:45.867 19881-19922/? E/godot: **ERROR**: The assembly 'GodotSharp' is out of sync.
2020-03-01 01:14:45.867 19881-19922/? E/godot:    At: modules/mono/mono_gd/gd_mono.cpp:926:_load_api_assemblies() - The assembly 'GodotSharp' is out of sync.
2020-03-01 01:14:45.867 19881-19922/? E/godot: **ERROR**: FATAL: Method failed.
2020-03-01 01:14:45.867 19881-19922/? E/godot:    At: modules/mono/mono_gd/gd_mono.cpp:937:_load_api_assemblies() - FATAL: Method failed.
2020-03-01 01:14:45.921 652-3426/system_process I/WindowManager: WIN DEATH: Window{a95de55 u0 game.package/com.godot.game.GodotApp}
2020-03-01 01:14:45.923 652-3667/system_process W/ActivityManager: Force removing ActivityRecord{3557d6 u0 game.package/com.godot.game.GodotApp t189}: app died, no saved state
2020-03-01 01:14:45.942 310-5913/? W/SurfaceFlinger: Attempting to destroy on removed layer: AppWindowToken{1ffd944 token=Token{cfdca57 ActivityRecord{3557d6 u0 game.package/com.godot.game.GodotApp t189}}}#0
2020-03-01 01:14:46.008 652-1257/system_process I/ActivityManager: Displayed game.package/com.godot.game.GodotApp: +991ms
akien-mga commented 4 years ago

Did you generate the mono glue with the exact same commit/modules? The assemblies used by your editor and your export templates are out of sync.

harmonicsolutions commented 4 years ago

I did not re-create the editor. I used official Godot mono 3.2 stable for mac. In ubuntu. i created branch from 3.2-stable tag. And I created export templates. export template creation is failed on mac for me. So I used ubuntu to create templates. And I used those templates in the official editor which is Godot mono 3.2 stable for Mac, file: Godot_v3.2-stable_mono_osx.64.zip.

So if i want to use custom export templates in osx editor, do i need to create them by using glue which is generated by osx binary?

if so, kinda mandatory to create editor on mac and templates on the mac right?

akien-mga commented 4 years ago

If any of the custom modules you added or existing modules that you disabled change the public API, then yes, you need to rebuild the editor too and regenerate the Mono glue for your templates build.

Can you give details on what changes you made in your custom build?

CC @neikeq

harmonicsolutions commented 4 years ago

I used the commands below to disable all the modules which i do not need for the game. And i ran the commands below on Ubuntu to be able to create Android export templates.

scons -j 6 platform=android --config=force target=release_debug android_arch=armv7 tools=no module_mono_enabled=yes deprecated=no minizip=no builtin_glew=no builtin_libmpcdec=no disable_advanced_gui=yes disable_3d=yes builtin_openssl=no module_openssl_enabled=no module_bmp_enabled=no builtin_libtheora=no builtin_libvorbis=no builtin_opus=no module_bullet_enabled=no module_csg_enabled=no builtin_speex=no builtin_squish=no builtin_zlib=no module_dds_enabled=no module_chibi_enabled=no module_enet_enabled=no module_gdnative_enabled=no module_gridmap_enabled=no module_hdr_enabled=no module_mbedtls_enabled=no module_jpg_enabled=no module_ik_enabled=no module_mobile_vr_enabled=no module_opus_enabled=no module_pvr_enabled=no module_recast_enabled=no module_regex_enabled=no module_squish_enabled=no module_mpc_enabled=no module_tga_enabled=no module_thekla_unwrap_enabled=no module_theora_enabled=no module_tinyexr_enabled=no module_vorbis_enabled=no module_webm_enabled=no module_websocket_enabled=no module_pbm_enabled=no module_speex_enabled=no module_etc_enabled=no mono_prefix=/media/sf_Data/android-armeabi-v7a-release

scons -j 6 platform=android --config=force target=release android_arch=armv7 tools=no module_mono_enabled=yes deprecated=no minizip=no builtin_glew=no builtin_libmpcdec=no disable_advanced_gui=yes disable_3d=yes builtin_openssl=no module_openssl_enabled=no module_bmp_enabled=no builtin_libtheora=no builtin_libvorbis=no builtin_opus=no module_bullet_enabled=no module_csg_enabled=no builtin_speex=no builtin_squish=no builtin_zlib=no module_dds_enabled=no module_chibi_enabled=no module_enet_enabled=no module_gdnative_enabled=no module_gridmap_enabled=no module_hdr_enabled=no module_mbedtls_enabled=no module_jpg_enabled=no module_ik_enabled=no module_mobile_vr_enabled=no module_opus_enabled=no module_pvr_enabled=no module_recast_enabled=no module_regex_enabled=no module_squish_enabled=no module_mpc_enabled=no module_tga_enabled=no module_thekla_unwrap_enabled=no module_theora_enabled=no module_tinyexr_enabled=no module_vorbis_enabled=no module_webm_enabled=no module_websocket_enabled=no module_pbm_enabled=no module_speex_enabled=no module_etc_enabled=no mono_prefix=/media/sf_Data/android-armeabi-v7a-release

It seems that i definitely need to find a way to create Android export template on mac. I can compile Mono glue and Mono editor on mac but when i try to build Android export i got shared lib issue first. Even if i copy required file, then i get the errors below and fails to create Android templates:

cannot find -lpthread cannot find -liconv

I tried so many different things to install these libs into mac but i was not successful. Basically i am stuck on mac. So I created ubuntu image to compile Android exports. I did not face this issue on ubuntu.

neikeq commented 4 years ago

This should be possible if done correctly. You may still get the ore API hash mismatch. error in the debug export template but not the The assembly 'GodotSharp' is out of sync. fatal error. The "out of sync" error happens when the C# API was generated with a different API hash than the C++ glue. How are you building the Godot binary that will generate the glue? Is it the same version as the Godot editor you use to export?

neikeq commented 4 years ago

About the linker errors on macOS. I think it's because of this: https://github.com/godotengine/godot/blob/e2b66cacf78ae39b94df748e9740b98a1f011e77/modules/mono/build_scripts/mono_configure.py#L243-L244

This variable: https://github.com/godotengine/godot/blob/e2b66cacf78ae39b94df748e9740b98a1f011e77/modules/mono/build_scripts/mono_configure.py#L166

Should be:

is_apple = env['platform'] in ['osx', 'iphone']
harmonicsolutions commented 4 years ago

It is the same version. I do create branch from 3.2-stable tag.

And then in Ubuntu (without GUI), i do run the commands below: As platform it only supports Android and Server. And Android cannot be used for mono glue generation, only option is to use server for platform.

scons p=server tools=yes module_mono_enabled=yes mono_glue=no -j 6

./bin/godot_server.x11.tools.64.mono --generate-mono-glue modules/mono/glue

neikeq commented 4 years ago

Can you run the following commands with both the editor and your server build?

godot --class-db-json

It should create the file user://class_db_api.json (the command will print the real path at the end).

Then upload both files or the diff here to see what's changed.

akien-mga commented 4 years ago

@neikeq: shouldn't the server build used to generate the glue have the same disabled modules as the template? Many modules register public APIs.

harmonicsolutions commented 4 years ago

Can you run the following commands with both the editor and your server build?

godot --class-db-json

It should create the file user://class_db_api.json (the command will print the real path at the end).

Then upload both files or the diff here to see what's changed.

I ran the command "./bin/godot_server.x11.tools.64.mono --class-db-json" in ubuntu.

I got the error: ERROR: initialize_load_assemblies: Mono: This binary was built with 'mono_glue=no'; cannot load assemblies.

Then I ran the command below:

scons p=server tools=yes target=release_debug module_mono_enabled=yes mono_glue=yes -j 6

But i got another error:

Errors in packages.config projects Unable to find version '2.1.1' of package 'DotNet.Glob'. /root/.nuget/packages/: Package 'DotNet.Glob.2.1.1' is not found on source '/root/.nuget/packages/'.

harmonicsolutions commented 4 years ago

About the linker errors on macOS. I think it's because of this: https://github.com/godotengine/godot/blob/e2b66cacf78ae39b94df748e9740b98a1f011e77/modules/mono/build_scripts/mono_configure.py#L243-L244

This variable: https://github.com/godotengine/godot/blob/e2b66cacf78ae39b94df748e9740b98a1f011e77/modules/mono/build_scripts/mono_configure.py#L166

Should be:

is_apple = env['platform'] in ['osx', 'iphone']

@neikeq I updated the code as you suggested in mono_configure.py file. I can create Android export templates without any problem on Mac now. I also used new custom templates on the editor which i complied. And I tested on mobile phone. Everything works perfectly now. Thanks a lot for your support.

I am not sure that this ticket is really needed anymore. Do you want me to close ticket?

ksvslk commented 4 years ago

Could anyone write down the steps what are needed to build Android export templates? I've built the Mono runtime for Android and now It is needed to generate the glue. There isn't an example in the documentation for the Mono version.

akien-mga commented 4 years ago

@ksvslk Everything is described in https://docs.godotengine.org/en/3.2/development/compiling/compiling_with_mono.html

Note that to generate the glue you need a tools=yes build (i.e. a desktop build for your host platform).

Then you need to build the Mono runtime for Android using the linked build scripts in https://github.com/godotengine/godot-mono-builds See https://docs.godotengine.org/en/3.2/development/compiling/compiling_with_mono.html#building-the-mono-runtime And then https://docs.godotengine.org/en/3.2/development/compiling/compiling_with_mono.html#targeting-android

ksvslk commented 4 years ago

@ksvslk Everything is described in https://docs.godotengine.org/en/3.2/development/compiling/compiling_with_mono.html

Note that to generate the glue you need a tools=yes build (i.e. a desktop build for your host platform).

Then you need to build the Mono runtime for Android using the linked build scripts in https://github.com/godotengine/godot-mono-builds See https://docs.godotengine.org/en/3.2/development/compiling/compiling_with_mono.html#building-the-mono-runtime And then https://docs.godotengine.org/en/3.2/development/compiling/compiling_with_mono.html#targeting-android

Okay. That was the thing - so I need to generate the glue for my host platform (not for Android in this case). But do I need to use the custom built editor then when exporting also?

akien-mga commented 4 years ago

But do I need to use the custom built editor then when exporting also?

Yes, when you do a custom build for templates, you most likely also need a custom build of the editor from the same commit. Otherwise the export might break if there are API changes between the version used in editor and in template.

ksvslk commented 4 years ago

But do I need to use the custom built editor then when exporting also?

Yes, when you do a custom build for templates, you most likely also need a custom build of the editor from the same commit. Otherwise the export might break if there are API changes between the version used in editor and in template.

Thanks for the help. To conclude:

Build temporary binary

scons p=windows tools=yes module_mono_enabled=yes mono_glue=no

Generate glue sources

bin\godot.windows.tools.64.mono --generate-mono-glue modules/mono/glue

Build binaries normally

Editor

scons p=windows target=release_debug tools=yes module_mono_enabled=yes

Export templates (use the Mono runtime built with the scripts found here: https://github.com/godotengine/godot-mono-builds)

scons p=android target=release_debug tools=no module_mono_enabled=yes scons p=android target=release tools=no module_mono_enabled=yes

One more question: Do I have to build the Mono runtime for Windows also (in the above case) using the same Mono version?