mirror of
https://github.com/godotengine/godot.git
synced 2024-11-15 16:43:10 +00:00
7f4ee36469
Like arm64v8, this is only supported by API 21 and later, so we enforce 21 as min API for x86_64. Part of #25030.
172 lines
5.8 KiB
Python
172 lines
5.8 KiB
Python
#!/usr/bin/env python
|
|
|
|
Import('env')
|
|
|
|
import shutil
|
|
from compat import open_utf8
|
|
from distutils.version import LooseVersion
|
|
from detect import get_ndk_version
|
|
|
|
android_files = [
|
|
|
|
'os_android.cpp',
|
|
'file_access_android.cpp',
|
|
'audio_driver_opensl.cpp',
|
|
'file_access_jandroid.cpp',
|
|
'dir_access_jandroid.cpp',
|
|
'thread_jandroid.cpp',
|
|
'audio_driver_jandroid.cpp',
|
|
'java_glue.cpp',
|
|
'java_class_wrapper.cpp',
|
|
# 'power_android.cpp'
|
|
]
|
|
|
|
env_android = env.Clone()
|
|
if env['target'] == "profile":
|
|
env_android.Append(CPPFLAGS=['-DPROFILER_ENABLED'])
|
|
|
|
android_objects = []
|
|
for x in android_files:
|
|
android_objects.append(env_android.SharedObject(x))
|
|
|
|
env_thirdparty = env_android.Clone()
|
|
env_thirdparty.disable_warnings()
|
|
android_objects.append(env_thirdparty.SharedObject('#thirdparty/misc/ifaddrs-android.cc'))
|
|
|
|
abspath = env.Dir(".").abspath
|
|
|
|
with open_utf8(abspath + "/build.gradle.template", "r") as gradle_basein:
|
|
gradle_text = gradle_basein.read()
|
|
|
|
gradle_maven_flat_text = ""
|
|
if len(env.android_flat_dirs) > 0:
|
|
gradle_maven_flat_text += "flatDir {\n"
|
|
gradle_maven_flat_text += "\tdirs "
|
|
for x in env.android_flat_dirs:
|
|
gradle_maven_flat_text += "'" + x + "',"
|
|
|
|
gradle_maven_flat_text = gradle_maven_flat_text[:-1]
|
|
gradle_maven_flat_text += "\n\t}\n"
|
|
|
|
gradle_maven_repos_text = ""
|
|
gradle_maven_repos_text += gradle_maven_flat_text
|
|
|
|
if len(env.android_maven_repos) > 0:
|
|
gradle_maven_repos_text += ""
|
|
for x in env.android_maven_repos:
|
|
gradle_maven_repos_text += "\tmaven {\n"
|
|
gradle_maven_repos_text += "\t" + x + "\n"
|
|
gradle_maven_repos_text += "\t}\n"
|
|
|
|
gradle_maven_dependencies_text = ""
|
|
|
|
for x in env.android_dependencies:
|
|
gradle_maven_dependencies_text += x + "\n\t"
|
|
|
|
gradle_java_dirs_text = ""
|
|
|
|
for x in env.android_java_dirs:
|
|
gradle_java_dirs_text += ",'" + x.replace("\\", "/") + "'"
|
|
|
|
gradle_plugins = ""
|
|
for x in env.android_gradle_plugins:
|
|
gradle_plugins += "apply plugin: \"" + x + "\"\n"
|
|
|
|
gradle_classpath = ""
|
|
for x in env.android_gradle_classpath:
|
|
gradle_classpath += "\t\tclasspath \"" + x + "\"\n"
|
|
|
|
gradle_res_dirs_text = ""
|
|
|
|
for x in env.android_res_dirs:
|
|
gradle_res_dirs_text += ",'" + x.replace("\\", "/") + "'"
|
|
|
|
gradle_aidl_dirs_text = ""
|
|
|
|
for x in env.android_aidl_dirs:
|
|
gradle_aidl_dirs_text += ",'" + x.replace("\\", "/") + "'"
|
|
|
|
gradle_jni_dirs_text = ""
|
|
|
|
for x in env.android_jni_dirs:
|
|
gradle_jni_dirs_text += ",'" + x.replace("\\", "/") + "'"
|
|
|
|
gradle_asset_dirs_text = ""
|
|
|
|
for x in env.android_asset_dirs:
|
|
gradle_asset_dirs_text += ",'" + x.replace("\\", "/") + "'"
|
|
|
|
gradle_default_config_text = ""
|
|
|
|
minSdk = 18
|
|
targetSdk = 28
|
|
|
|
for x in env.android_default_config:
|
|
if x.startswith("minSdkVersion") and int(x.split(" ")[-1]) < minSdk:
|
|
x = "minSdkVersion " + str(minSdk)
|
|
if x.startswith("targetSdkVersion") and int(x.split(" ")[-1]) > targetSdk:
|
|
x = "targetSdkVersion " + str(targetSdk)
|
|
|
|
gradle_default_config_text += x + "\n\t\t"
|
|
|
|
if "minSdkVersion" not in gradle_default_config_text:
|
|
gradle_default_config_text += ("minSdkVersion " + str(minSdk) + "\n\t\t")
|
|
|
|
if "targetSdkVersion" not in gradle_default_config_text:
|
|
gradle_default_config_text += ("targetSdkVersion " + str(targetSdk) + "\n\t\t")
|
|
|
|
gradle_text = gradle_text.replace("$$GRADLE_REPOSITORY_URLS$$", gradle_maven_repos_text)
|
|
gradle_text = gradle_text.replace("$$GRADLE_DEPENDENCIES$$", gradle_maven_dependencies_text)
|
|
gradle_text = gradle_text.replace("$$GRADLE_JAVA_DIRS$$", gradle_java_dirs_text)
|
|
gradle_text = gradle_text.replace("$$GRADLE_RES_DIRS$$", gradle_res_dirs_text)
|
|
gradle_text = gradle_text.replace("$$GRADLE_ASSET_DIRS$$", gradle_asset_dirs_text)
|
|
gradle_text = gradle_text.replace("$$GRADLE_AIDL_DIRS$$", gradle_aidl_dirs_text)
|
|
gradle_text = gradle_text.replace("$$GRADLE_JNI_DIRS$$", gradle_jni_dirs_text)
|
|
gradle_text = gradle_text.replace("$$GRADLE_DEFAULT_CONFIG$$", gradle_default_config_text)
|
|
gradle_text = gradle_text.replace("$$GRADLE_PLUGINS$$", gradle_plugins)
|
|
gradle_text = gradle_text.replace("$$GRADLE_CLASSPATH$$", gradle_classpath)
|
|
|
|
with open_utf8(abspath + "/java/build.gradle", "w") as gradle_baseout:
|
|
gradle_baseout.write(gradle_text)
|
|
|
|
|
|
with open_utf8(abspath + "/AndroidManifest.xml.template", "r") as pp_basein:
|
|
manifest = pp_basein.read()
|
|
|
|
manifest = manifest.replace("$$ADD_APPLICATION_CHUNKS$$", env.android_manifest_chunk)
|
|
manifest = manifest.replace("$$ADD_PERMISSION_CHUNKS$$", env.android_permission_chunk)
|
|
manifest = manifest.replace("$$ADD_APPATTRIBUTE_CHUNKS$$", env.android_appattributes_chunk)
|
|
|
|
with open_utf8(abspath + "/java/AndroidManifest.xml", "w") as pp_baseout:
|
|
pp_baseout.write(manifest)
|
|
|
|
|
|
lib = env_android.add_shared_library("#bin/libgodot", [android_objects], SHLIBSUFFIX=env["SHLIBSUFFIX"])
|
|
|
|
lib_arch_dir = ''
|
|
if env['android_arch'] == 'armv6':
|
|
lib_arch_dir = 'armeabi'
|
|
elif env['android_arch'] == 'armv7':
|
|
lib_arch_dir = 'armeabi-v7a'
|
|
elif env['android_arch'] == 'arm64v8':
|
|
lib_arch_dir = 'arm64-v8a'
|
|
elif env['android_arch'] == 'x86':
|
|
lib_arch_dir = 'x86'
|
|
elif env['android_arch'] == 'x86_64':
|
|
lib_arch_dir = 'x86_64'
|
|
else:
|
|
print('WARN: Architecture not suitable for embedding into APK; keeping .so at \\bin')
|
|
|
|
if lib_arch_dir != '':
|
|
if env['target'] == 'release':
|
|
lib_type_dir = 'release'
|
|
else: # release_debug, debug
|
|
lib_type_dir = 'debug'
|
|
|
|
out_dir = '#platform/android/java/libs/' + lib_type_dir + '/' + lib_arch_dir
|
|
env_android.Command(out_dir + '/libgodot_android.so', '#bin/libgodot' + env['SHLIBSUFFIX'], Move("$TARGET", "$SOURCE"))
|
|
ndk_version = get_ndk_version(env["ANDROID_NDK_ROOT"])
|
|
if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"):
|
|
stl_lib_path = str(env['ANDROID_NDK_ROOT']) + '/sources/cxx-stl/llvm-libc++/libs/' + lib_arch_dir + '/libc++_shared.so'
|
|
env_android.Command(out_dir + '/libc++_shared.so', stl_lib_path, Copy("$TARGET", "$SOURCE"))
|