godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.67k stars 503 forks source link

Cannot generate bindings on android #329

Open piiertho opened 4 years ago

piiertho commented 4 years ago

Hi there ! I am testing new merged PR for android, to see if I can getting it working with fmod gdnative. Here is the project structure I use to test:

rootTestProject
    - godot-cpp (with headers in submodule)
    - Fmod-gdnative
    - libs (containing fmod api)

I work from OSX.

I have no problem generating bindings for OSX. Here is output for android build:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
/Users/piertho/Library/android-sdks/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -o src/core/Basis.o -c --target=aarch64-linux-android21 -march=armv8-a -fPIC -I. -Igodot_headers -Iinclude -Iinclude/gen -Iinclude/core src/core/Basis.cpp
In file included from src/core/Basis.cpp:1:
In file included from include/core/Basis.hpp:4:
In file included from godot_headers/gdnative/basis.h:54:
In file included from godot_headers/gdnative/gdnative.h:141:
godot_headers/gdnative/string.h:39:10: fatal error: 'wchar.h' file not found
#include <wchar.h>
         ^~~~~~~~~
1 error generated.
scons: *** [src/core/Basis.o] Error 1
scons: building terminated because of errors.

I first tried to generate bindings with:

scons platform=android generate_bindings=yes ANDROID_NDK_ROOT="/Users/piertho/Library/android-sdks/ndk-bundle" android_arch=arm64v8

Same problem if I set ANDROID_NDK_ROOT as OS environment variable and run:

scons platform=android generate_bindings=yes android_arch=arm64v8

So I tried to compile godot engine and add its executable path in command running:

scons godotbinpath="../godot/bin/godot.osx.tools.64" platform=android generate_bindings=yes ANDROID_NDK_ROOT="/Users/piertho/Library/android-sdks/ndk-bundle" android_arch=arm64v8

And I get the same output with that.

Then as a last try, I generated a new api.json from godot engine build and ran:

scons godotbinpath="../godot/bin/godot.osx.tools.64" platform=android generate_bindings=yes ANDROID_NDK_ROOT="/Users/piertho/Library/android-sdks/ndk-bundle" android_arch=arm64v8 use_custom_api_file=yes custom_api_file=api.json

(I put api.json in godot-cpp folder) I get the same error with that.

@BastiaanOlij and @TGRCdev I need your help to finish testing new merged PR ;)

CedNaru commented 4 years ago

I followed the exact same step than @piiertho but on Windows. I get the same error.


D:\Developpement\repoffi\godot-cpp>scons godotbinpath="../godot/bin/godot.windows.opt.tools.64.exe" platform=android generate_bindings=yes ANDROID_NDK_ROOT="C:/Android/NDK" android_arch=arm64v8
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
C:/Android/NDK/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++ -o src\core\AABB.o -c --target=aarch64-linux-android21 -march=armv8-a -fPIC -I. -Igodot_headers -Iinclude -Iinclude\gen -Iinclude\core src\core\AABB.cpp
=====
In file included from src\core\AABB.cpp:1:
In file included from include\core\AABB.hpp:4:
In file included from include\core/Vector3.hpp:4:
In file included from godot_headers\gdnative/vector3.h:54:
In file included from godot_headers\gdnative/basis.h:54:
In file included from godot_headers\gdnative/gdnative.h:141:
godot_headers\gdnative/string.h:39:10: fatal error: 'wchar.h' file not found
#include <wchar.h>
         ^~~~~~~~~
1 error generated. ```
TGRCdev commented 4 years ago

I'm trying to reproduce this. I created a blank Windows 10 virtual machine, and only installed Git, Scons and the NDK, and it was still able to compile fine.

It seems like Scons isn't properly setting the sysroot during NDK compile, but NDK's clang scripts should do that automatically. I'm not sure how this is happening.

Could you try re-downloading your NDK? Maybe some of the headers got deleted by accident at some point.

CedNaru commented 4 years ago

I'm using the 16b NDK version (because that only one that worked for me when I compile the engine for android). What version do you use ?

piiertho commented 4 years ago

Same version than @CedNaru. I can use it to build for android with my PR. I'll try with new sdk to see if it cause the problem.

piiertho commented 4 years ago

Sorry for double message. Here are my test results ! (Done with a windows linux kernel)

It compiles well with ndk20. But I think we have to check wich ndk version works with godot engine itself. I sucessfully compiled fmod gdnative with it.

I did not try to run it for now, I have to export my project and I am not at home ^^ I have some reserves on ENV variables. I think not all is defined in the current scons version like it is told in this documentation (I can add them if you want, it is the same thing than in my PR)

Also I can add travis-ci job (pretty much the same than in my PR).

If I resume, I think we should:

I propose myself to do the job for two last items, and when those are ready, I would make a specific PR for iOS. What you guys think about this plan ?

TGRCdev commented 4 years ago

I've compiled Godot and gdsqlite with ndk20 and it has ran on my device fine, but I can modify SCons to use other NDK versions and see which versions work.

The NDK version is stored in the source.properties file for ndk11 and up. The current build system works with ndk19 and up because they support in-place toolchain usage. Versions lower than that will require using make_standalone_toolchain.py before compiling.

piiertho commented 4 years ago

I confirm that I am able to generate Android export templates with ndk20. On an other hand, it seems that in place toolchain is a better way than differenciated ones in many cases, according to Android ndk documentation. So I will start working on two next steps and make a new PR :)

piiertho commented 4 years ago

330 adds travis-ci and missing toolchain components :)

TGRCdev commented 4 years ago

331 updates the SConstruct file with special cases for older NDK revisions. If it can't use in-place toolchains, it will call make_standalone_toolchain.py. It will also accept a pre-built toolchain with ndk_toolchain.