diff options
author | Ruslan Mustakov <r.mustakov@gmail.com> | 2017-08-18 21:17:35 +0700 |
---|---|---|
committer | Ruslan Mustakov <r.mustakov@gmail.com> | 2017-08-30 18:14:19 +0700 |
commit | 5ccdeccb6ed6b8480a86b0db36f192526cba1274 (patch) | |
tree | eafb890997ee985210b66272957aa22ad00df125 /platform/android/export | |
parent | 8b9026c05e9982a7bc0c7f52776ad74276b90252 (diff) |
Make GDNative work on Android
The changes include work done to ensure that GDNative apps and Nim
integration specifically can run on Android. The changes have been
tested on our WIP game, which uses godot-nim and depends on several
third-party .so libs, and Platformer demo to ensure nothing got broken.
- .so libraries are exported to lib/ folder in .apk, instead of assets/,
because that's where Android expects them to be and it resolves the
library name into "lib/<ABI>/<name>", where <ABI> is the ABI matching
the current device. So we establish the convention that Android .so
files in the project must be located in the folder corresponding to
the ABI they were compiled for.
- Godot callbacks (event handlers) are now called from the same thread
from which Main::iteration is called. It is also what Godot now
considers to be the main thread, because Main::setup is also called
from there. This makes threading on Android more consistent with
other platforms, making the code that depends on Thread::get_main_id
more portable (GDNative has such code).
- Sizes of GDNative API types have been fixed to work on 32-bit
platforms.
Diffstat (limited to 'platform/android/export')
-rw-r--r-- | platform/android/export/export.cpp | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 8b3a64bbe6..da1b2617ef 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -468,11 +468,36 @@ class EditorExportAndroid : public EditorExportPlatform { return zipfi; } - static Error save_apk_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) { + static Set<String> get_abis() { + Set<String> abis; + abis.insert("armeabi"); + abis.insert("armeabi-v7a"); + abis.insert("arm64-v8a"); + abis.insert("x86"); + abis.insert("x86_64"); + abis.insert("mips"); + abis.insert("mips64"); + return abis; + } + static Error save_apk_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) { APKExportData *ed = (APKExportData *)p_userdata; String dst_path = p_path; - dst_path = dst_path.replace_first("res://", "assets/"); + static Set<String> android_abis = get_abis(); + + if (dst_path.ends_with(".so")) { + String abi = dst_path.get_base_dir().get_file().strip_edges(); // parent dir name + if (android_abis.has(abi)) { + dst_path = "lib/" + abi + "/" + dst_path.get_file(); + } else { + String err = "Dynamic libraries must be located in the folder named after Android ABI they were compiled for. " + + p_path + " does not follow this convention."; + ERR_PRINT(err.utf8().get_data()); + return ERR_FILE_BAD_PATH; + } + } else { + dst_path = dst_path.replace_first("res://", "assets/"); + } zip_fileinfo zipfi = get_zip_fileinfo(); @@ -1375,15 +1400,15 @@ public: } } - if (file == "lib/x86/libgodot_android.so" && !export_x86) { + if (file == "lib/x86/*.so" && !export_x86) { skip = true; } - if (file.match("lib/armeabi*/libgodot_android.so") && !export_arm) { + if (file.match("lib/armeabi*/*.so") && !export_arm) { skip = true; } - if (file.match("lib/arm64*/libgodot_android.so") && !export_arm64) { + if (file.match("lib/arm64*/*.so") && !export_arm64) { skip = true; } |