You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-18 14:21:41 +00:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user