0.2.0-dev Download ZIP
118 lines ·3.8 KB Raw
| 1 | #!/usr/bin/env python |
| 2 | from misc.utility.scons_hints import * |
| 3 | |
| 4 | import platform |
| 5 | import sys |
| 6 | |
| 7 | import platform_android_builders |
| 8 | |
| 9 | from methods import print_warning |
| 10 | |
| 11 | Import("env") |
| 12 | |
| 13 | android_files = [ |
| 14 | "os_android.cpp", |
| 15 | "android_input_handler.cpp", |
| 16 | "file_access_android.cpp", |
| 17 | "file_access_filesystem_jandroid.cpp", |
| 18 | "audio_driver_opensl.cpp", |
| 19 | "dir_access_jandroid.cpp", |
| 20 | "tts_android.cpp", |
| 21 | "thread_jandroid.cpp", |
| 22 | "net_socket_android.cpp", |
| 23 | "java_godot_lib_jni.cpp", |
| 24 | "java_class_wrapper.cpp", |
| 25 | "java_godot_wrapper.cpp", |
| 26 | "java_godot_view_wrapper.cpp", |
| 27 | "java_godot_io_wrapper.cpp", |
| 28 | "jni_utils.cpp", |
| 29 | "android_keys_utils.cpp", |
| 30 | "display_server_android.cpp", |
| 31 | "plugin/godot_plugin_jni.cpp", |
| 32 | "rendering_context_driver_vulkan_android.cpp", |
| 33 | "variant/callable_jni.cpp", |
| 34 | "dialog_utils_jni.cpp", |
| 35 | "editor/game_menu_utils_jni.cpp", |
| 36 | "editor/editor_utils_jni.cpp", |
| 37 | ] |
| 38 | |
| 39 | env_android = env.Clone() |
| 40 | |
| 41 | android_objects = [] |
| 42 | for x in android_files: |
| 43 | android_objects.append(env_android.SharedObject(x)) |
| 44 | |
| 45 | env_thirdparty = env_android.Clone() |
| 46 | env_thirdparty.disable_warnings() |
| 47 | thirdparty_obj = env_thirdparty.SharedObject("#thirdparty/misc/ifaddrs-android.cc") |
| 48 | android_objects.append(thirdparty_obj) |
| 49 | |
| 50 | # FIXME: Hardcoded to bin to ensure the directory exists if not redirecting build objects. |
| 51 | lib = env_android.add_shared_library("#bin/libgodot", android_objects, redirect_build_objects=False) |
| 52 | |
| 53 | # Needed to force rebuilding the platform files when the thirdparty code is updated. |
| 54 | env.Depends(lib, thirdparty_obj) |
| 55 | |
| 56 | lib_arch_dir = "" |
| 57 | triple_target_dir = "" |
| 58 | if env["arch"] == "arm32": |
| 59 | lib_arch_dir = "armeabi-v7a" |
| 60 | triple_target_dir = "arm-linux-androideabi" |
| 61 | elif env["arch"] == "arm64": |
| 62 | lib_arch_dir = "arm64-v8a" |
| 63 | triple_target_dir = "aarch64-linux-android" |
| 64 | elif env["arch"] == "x86_32": |
| 65 | lib_arch_dir = "x86" |
| 66 | triple_target_dir = "i686-linux-android" |
| 67 | elif env["arch"] == "x86_64": |
| 68 | lib_arch_dir = "x86_64" |
| 69 | triple_target_dir = "x86_64-linux-android" |
| 70 | else: |
| 71 | print_warning("Architecture not suitable for embedding into APK; keeping .so at \\bin") |
| 72 | |
| 73 | host_subpath = "" |
| 74 | if sys.platform.startswith("linux"): |
| 75 | host_subpath = "linux-x86_64" |
| 76 | elif sys.platform.startswith("darwin"): |
| 77 | host_subpath = "darwin-x86_64" |
| 78 | elif sys.platform.startswith("win"): |
| 79 | if platform.machine().endswith("64"): |
| 80 | host_subpath = "windows-x86_64" |
| 81 | else: |
| 82 | host_subpath = "windows" |
| 83 | |
| 84 | if lib_arch_dir != "" and host_subpath != "": |
| 85 | if env.debug_features: |
| 86 | if env.editor_build and env["store_release"]: |
| 87 | lib_type_dir = "release" |
| 88 | else: |
| 89 | lib_type_dir = "debug" |
| 90 | else: # Release |
| 91 | lib_type_dir = "release" |
| 92 | |
| 93 | if env.editor_build: |
| 94 | lib_tools_dir = "tools/" |
| 95 | else: |
| 96 | lib_tools_dir = "" |
| 97 | |
| 98 | jni_libs_dir = "#platform/android/java/lib/libs/" + lib_tools_dir + lib_type_dir + "/" |
| 99 | out_dir = jni_libs_dir + lib_arch_dir |
| 100 | env_android.CommandNoCache(out_dir + "/libgodot_android.so", lib, Move("$TARGET", "$SOURCE")) |
| 101 | |
| 102 | stl_lib_path = f"{env['ANDROID_NDK_ROOT']}/toolchains/llvm/prebuilt/{host_subpath}/sysroot/usr/lib/{triple_target_dir}/libc++_shared.so" |
| 103 | env_android.CommandNoCache(out_dir + "/libc++_shared.so", stl_lib_path, Copy("$TARGET", "$SOURCE")) |
| 104 | |
| 105 | if env["debug_symbols"] and env["separate_debug_symbols"]: |
| 106 | debug_symbols_zip_file = ( |
| 107 | ("#bin/android-editor-" if env.editor_build else "#bin/android-template-") |
| 108 | + lib_type_dir |
| 109 | + "-native-symbols.zip" |
| 110 | ) |
| 111 | env_android.NoCache(Zip(debug_symbols_zip_file, jni_libs_dir, ZIPROOT=Dir(jni_libs_dir))) |
| 112 | |
| 113 | if env["generate_android_binaries"]: |
| 114 | env_android.AlwaysBuild( |
| 115 | env_android.CommandNoCache( |
| 116 | "generate_android_binaries", lib, env.Run(platform_android_builders.generate_android_binaries) |
| 117 | ) |
| 118 | ) |