| 1 |
|
| 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 |
|
| 51 |
lib = env_android.add_shared_library("#bin/libgodot", android_objects, redirect_build_objects=False) |
| 52 |
|
| 53 |
|
| 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.dev_build: |
| 86 |
lib_type_dir = "dev" |
| 87 |
elif env.debug_features: |
| 88 |
if env.editor_build and env["store_release"]: |
| 89 |
lib_type_dir = "release" |
| 90 |
else: |
| 91 |
lib_type_dir = "debug" |
| 92 |
else: |
| 93 |
lib_type_dir = "release" |
| 94 |
|
| 95 |
if env.editor_build: |
| 96 |
lib_tools_dir = "tools/" |
| 97 |
else: |
| 98 |
lib_tools_dir = "" |
| 99 |
|
| 100 |
jni_libs_dir = "#platform/android/java/lib/libs/" + lib_tools_dir + lib_type_dir + "/" |
| 101 |
out_dir = jni_libs_dir + lib_arch_dir |
| 102 |
env_android.CommandNoCache(out_dir + "/libgodot_android.so", lib, Move("$TARGET", "$SOURCE")) |
| 103 |
|
| 104 |
stl_lib_path = f"{env['ANDROID_NDK_ROOT']}/toolchains/llvm/prebuilt/{host_subpath}/sysroot/usr/lib/{triple_target_dir}/libc++_shared.so" |
| 105 |
env_android.CommandNoCache(out_dir + "/libc++_shared.so", stl_lib_path, Copy("$TARGET", "$SOURCE")) |
| 106 |
|
| 107 |
if env["debug_symbols"] and env["separate_debug_symbols"]: |
| 108 |
debug_symbols_zip_file = ( |
| 109 |
("#bin/android-editor-" if env.editor_build else "#bin/android-template-") |
| 110 |
+ lib_type_dir |
| 111 |
+ "-native-symbols.zip" |
| 112 |
) |
| 113 |
env_android.NoCache(Zip(debug_symbols_zip_file, jni_libs_dir, ZIPROOT=Dir(jni_libs_dir))) |
| 114 |
|
| 115 |
if env["generate_android_binaries"]: |
| 116 |
env_android.AlwaysBuild( |
| 117 |
env_android.CommandNoCache( |
| 118 |
"generate_android_binaries", lib, env.Run(platform_android_builders.generate_android_binaries) |
| 119 |
) |
| 120 |
) |