godotengine/gdnative-demos

what about android/ios builds

Opened this issue · 13 comments

Are there any examples of Android/IOS builds. I noticed those are not listed in scons?

iOS is a bit of a hard one because iOS doesn't allow dynamic libraries. @endragor and @karroffel did heaps of work to allow you to statically compile a GDNative library on iOS but how this works, I don't know.

I would really like an Android example too because I need it. If someone can help out I'll update the C example to also include Android instructions

I managed to work out GDNative for Android on my project, here's a zip file with the .mk files: jni.zip
The .mk files in the zip are pretty generic so I guess they can work in demos or other projects. Though you should change the LOCAL_MODULE := libshawynative.android line.

Note: I've only tested this using nativescript-1.0

ArdaE commented

Has there been any progress on this?

After spending a day, I got quite far in trying to build a GDNative C++ module for iOS, but now I'm stuck with unresolved symbols for the following:

- godot::Variant::operator float() const
- godot::Godot::gdnative_terminate(godot_gdnative_terminate_options*)
- godot::Node2D::set_position(godot::Vector2)
- godot::Variant::~Variant()
- _api
- godot::Godot::nativescript_init(void*)
- _nativescript_api
- godot::_RegisterState::nativescript_handle
- godot::Godot::gdnative_init(godot_gdnative_init_options*)
- _nativescript_1_1_api
- godot::Variant::Variant(godot::Variant const&)
- godot::_TagDB::register_type(unsigned long, unsigned long)

Assuming I need the C++ bindings for iOS to resolve these issues, I've tried the following, but it failed because the iOS platform is not defined in the SConstruct of godot-cpp:

scons platform=iOS generate_bindings=yes

After some digging on how to build the C++ bindings for iOS, I came across a PR that's waiting to be merged.

So I guess currently GDNative C++ for iOS (and possibly Android) is not only undocumented, but it is not even possible without the PR I've linked above.

In case it's helpful, in the process of researching this topic (for this post) I found this seemingly complete write-up for Android which looks pretty comprehensive:

Also, cross-linking to related issue: godotengine/godot-headers#30

Edit: Added link to Reddit thread.

Now that the pull request above is merged, is there any way to make gdnative libaries for iOS now?

It has always been possible (since 3.0). You'd just compile a static library instead of a dynamic one.

@endragor Great! So how do you do it?
It doesn't show how neither here nor in the godot cpp bindings repo.

Compile a static library (.a) and specify it in the .gdnlib file for iOS platform. There isn't anything specific beside using static library instead of a dynamic one.

@endragor And how do you do that? The compiling part.
Again, lack of documentation here.

About build for Android, i've proposed this pull-request #30, closed without being merged.

@Didifred The repo has changed a lot since that PR was closed, we now have nice SConstructs for each project, but they are only for desktop at the moment. Improvements are welcome. If someone were to submit another PR that adds Android or iOS support to these new SConstructs, and adds instructions to the READMEs, I would review and merge it in a timely manner.

I created a gdnative example that successfully compiles the ios version

gdnative_example_mac_ios