godotengine / godot

Godot Engine ā€“ Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.23k stars 21.04k forks source link

Android AAR plugin is not loaded #56500

Closed BastiaanOlij closed 1 year ago

BastiaanOlij commented 2 years ago

Godot version

3.x (22a7e6b120569554ed065414f565bdf6dd3771cf)

System information

Windows/Android

Issue description

While working on the port of the ARCore functionality from the core PR to a GDNative plugin, noticed the plugin stopped loading even though the .gdap file is in place. Investigating the generated APK I can see the correct files are put into place.

Best I can tell the difference is that we now remove the entry in the project.godot for the .gdnlib file when this file is not present in the project:

[gdnative]

singletons=[  ]

When plugins are build as an AAR file the .gdnlib file is encapsulated in the AAR file and not part of the project and thus not accessible by the editor.

The Oculus mobile plugin that uses this same approach has several GDNative objects that are loaded through scripts and they trigger the load of the library. In the ARCore module we don't have objects initialised through .gdns files, we only have our XR singleton object.

The workaround I'm using for now is that I've added a dummy object that needs to be instantiated through script to trigger the library load.

Steps to reproduce

Easiest is to compile the plugin discussed in this PR: https://github.com/GodotVR/godot_arcore/pull/6

Minimal reproduction project

https://github.com/GodotVR/godot_arcore/pull/6

BastiaanOlij commented 2 years ago

@m4gr3d raised this so it stays on the radar, could use your feedback in case I'm doing something wrong with the AAR.

neoncube2 commented 2 years ago

@BastiaanOlij I think I'm running into this same issue. Do you have an example of how to add a dummy project and instantiate is through the script? I'm not sure how to export an object from my .aar file.

Thanks :)

neoncube2 commented 2 years ago

@BastiaanOlij On second thought, I think that the issue that I'm running into may be different from yours. I'm building an Android plugin that doesn't have a native component, while yours has a native component.

BastiaanOlij commented 2 years ago

That shouldn't matter for recognizing and embedding the AAR, just changes what is included and loaded. Note that many of my initial findings here were wrong. I probably should close this issue. The ARCore plugin (while not functional yet) does load properly now.

That said, this whole process could use some better documentation.

neoncube2 commented 2 years ago

Ya, I think my problem must be different šŸ™‚ Godot is seeing my Android plugin and letting me enable it, but when I call Engine.get_singleton("StepsPlugin"), it always returns null.

BastiaanOlij commented 1 year ago

I'm closing this as outdated. We've been using AARs successfully for some time now (see OpenXR plugin in Godot 3 and OpenXR loaders in Godot 4)