2016-10-17 08:50:25 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-09-28 13:29:52 +02:00
|
|
|
Import('env')
|
|
|
|
|
2017-08-26 18:53:49 +02:00
|
|
|
from compat import open_utf8
|
2018-08-23 00:02:47 +02:00
|
|
|
from distutils.version import LooseVersion
|
|
|
|
from detect import get_ndk_version
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
android_files = [
|
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
'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',
|
2019-03-13 13:51:55 +01:00
|
|
|
'java_godot_lib_jni.cpp',
|
2017-03-21 03:31:41 +01:00
|
|
|
'java_class_wrapper.cpp',
|
2019-03-13 13:51:55 +01:00
|
|
|
'java_godot_wrapper.cpp',
|
|
|
|
'java_godot_io_wrapper.cpp',
|
2017-03-21 03:31:41 +01:00
|
|
|
# 'power_android.cpp'
|
2014-02-10 02:10:30 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
env_android = env.Clone()
|
|
|
|
if env['target'] == "profile":
|
2016-10-30 18:44:57 +01:00
|
|
|
env_android.Append(CPPFLAGS=['-DPROFILER_ENABLED'])
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
android_objects = []
|
2014-02-10 02:10:30 +01:00
|
|
|
for x in android_files:
|
2016-10-30 18:57:40 +01:00
|
|
|
android_objects.append(env_android.SharedObject(x))
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-10-03 15:14:54 +02:00
|
|
|
env_thirdparty = env_android.Clone()
|
|
|
|
env_thirdparty.disable_warnings()
|
2018-12-20 10:38:05 +01:00
|
|
|
android_objects.append(env_thirdparty.SharedObject('#thirdparty/misc/ifaddrs-android.cc'))
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
abspath = env.Dir(".").abspath
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-03-10 18:37:33 +01:00
|
|
|
with open_utf8(abspath + "/build.gradle.template", "r") as gradle_basein:
|
|
|
|
gradle_text = gradle_basein.read()
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-10-07 11:40:17 +02:00
|
|
|
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"
|
2018-07-03 23:28:24 +02:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_maven_repos_text = ""
|
2017-10-07 11:40:17 +02:00
|
|
|
gradle_maven_repos_text += gradle_maven_flat_text
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-01-09 14:21:22 +01:00
|
|
|
if len(env.android_maven_repos) > 0:
|
2017-03-05 11:16:55 +01:00
|
|
|
gradle_maven_repos_text += ""
|
2016-10-30 18:44:57 +01:00
|
|
|
for x in env.android_maven_repos:
|
2017-03-05 11:16:55 +01:00
|
|
|
gradle_maven_repos_text += "\tmaven {\n"
|
2017-04-10 05:04:40 +02:00
|
|
|
gradle_maven_repos_text += "\t" + x + "\n"
|
2017-03-05 11:16:55 +01:00
|
|
|
gradle_maven_repos_text += "\t}\n"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_maven_dependencies_text = ""
|
2016-01-08 17:36:44 +01:00
|
|
|
|
|
|
|
for x in env.android_dependencies:
|
2017-04-10 05:04:40 +02:00
|
|
|
gradle_maven_dependencies_text += x + "\n\t"
|
2016-01-08 17:36:44 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_java_dirs_text = ""
|
2016-01-08 17:36:44 +01:00
|
|
|
|
|
|
|
for x in env.android_java_dirs:
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_java_dirs_text += ",'" + x.replace("\\", "/") + "'"
|
2016-01-08 17:36:44 +01:00
|
|
|
|
2017-03-06 11:04:21 +01:00
|
|
|
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"
|
2017-09-20 06:49:33 +02:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_res_dirs_text = ""
|
2016-01-08 17:36:44 +01:00
|
|
|
|
|
|
|
for x in env.android_res_dirs:
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_res_dirs_text += ",'" + x.replace("\\", "/") + "'"
|
2016-01-08 17:36:44 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_aidl_dirs_text = ""
|
2016-01-08 17:36:44 +01:00
|
|
|
|
|
|
|
for x in env.android_aidl_dirs:
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_aidl_dirs_text += ",'" + x.replace("\\", "/") + "'"
|
2016-01-08 17:36:44 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_jni_dirs_text = ""
|
2016-01-08 17:36:44 +01:00
|
|
|
|
|
|
|
for x in env.android_jni_dirs:
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_jni_dirs_text += ",'" + x.replace("\\", "/") + "'"
|
2016-01-08 17:36:44 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_asset_dirs_text = ""
|
2016-01-08 17:36:44 +01:00
|
|
|
|
2018-07-03 23:28:24 +02:00
|
|
|
for x in env.android_asset_dirs:
|
|
|
|
gradle_asset_dirs_text += ",'" + x.replace("\\", "/") + "'"
|
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_default_config_text = ""
|
2016-07-06 21:03:50 +02:00
|
|
|
|
2017-09-20 06:49:33 +02:00
|
|
|
minSdk = 18
|
2018-12-03 22:46:43 +01:00
|
|
|
targetSdk = 28
|
2017-04-09 23:35:34 +02:00
|
|
|
|
2016-07-06 21:03:50 +02:00
|
|
|
for x in env.android_default_config:
|
2017-09-20 06:49:33 +02:00
|
|
|
if x.startswith("minSdkVersion") and int(x.split(" ")[-1]) < minSdk:
|
2017-04-09 23:35:34 +02:00
|
|
|
x = "minSdkVersion " + str(minSdk)
|
2017-09-20 06:49:33 +02:00
|
|
|
if x.startswith("targetSdkVersion") and int(x.split(" ")[-1]) > targetSdk:
|
2017-04-09 23:35:34 +02:00
|
|
|
x = "targetSdkVersion " + str(targetSdk)
|
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
gradle_default_config_text += x + "\n\t\t"
|
2016-07-06 21:03:50 +02:00
|
|
|
|
2017-04-09 23:35:34 +02:00
|
|
|
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")
|
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
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)
|
2017-03-06 11:04:21 +01:00
|
|
|
gradle_text = gradle_text.replace("$$GRADLE_PLUGINS$$", gradle_plugins)
|
|
|
|
gradle_text = gradle_text.replace("$$GRADLE_CLASSPATH$$", gradle_classpath)
|
2016-01-08 17:36:44 +01:00
|
|
|
|
2018-03-10 18:37:33 +01:00
|
|
|
with open_utf8(abspath + "/java/build.gradle", "w") as gradle_baseout:
|
|
|
|
gradle_baseout.write(gradle_text)
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-03-10 18:37:33 +01:00
|
|
|
with open_utf8(abspath + "/AndroidManifest.xml.template", "r") as pp_basein:
|
|
|
|
manifest = pp_basein.read()
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
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)
|
2018-03-10 18:37:33 +01:00
|
|
|
|
|
|
|
with open_utf8(abspath + "/java/AndroidManifest.xml", "w") as pp_baseout:
|
|
|
|
pp_baseout.write(manifest)
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
|
2017-11-28 21:27:57 +01:00
|
|
|
lib = env_android.add_shared_library("#bin/libgodot", [android_objects], SHLIBSUFFIX=env["SHLIBSUFFIX"])
|
2016-06-15 15:21:18 +02:00
|
|
|
|
|
|
|
lib_arch_dir = ''
|
|
|
|
if env['android_arch'] == 'armv6':
|
2016-10-30 18:44:57 +01:00
|
|
|
lib_arch_dir = 'armeabi'
|
2016-06-15 15:21:18 +02:00
|
|
|
elif env['android_arch'] == 'armv7':
|
2016-10-30 18:44:57 +01:00
|
|
|
lib_arch_dir = 'armeabi-v7a'
|
2017-07-25 12:28:31 +02:00
|
|
|
elif env['android_arch'] == 'arm64v8':
|
|
|
|
lib_arch_dir = 'arm64-v8a'
|
2016-06-15 15:21:18 +02:00
|
|
|
elif env['android_arch'] == 'x86':
|
2016-10-30 18:44:57 +01:00
|
|
|
lib_arch_dir = 'x86'
|
2019-01-16 11:16:00 +01:00
|
|
|
elif env['android_arch'] == 'x86_64':
|
|
|
|
lib_arch_dir = 'x86_64'
|
2016-06-15 15:21:18 +02:00
|
|
|
else:
|
2017-08-26 18:53:49 +02:00
|
|
|
print('WARN: Architecture not suitable for embedding into APK; keeping .so at \\bin')
|
2016-06-15 15:21:18 +02:00
|
|
|
|
|
|
|
if lib_arch_dir != '':
|
2016-10-30 18:44:57 +01:00
|
|
|
if env['target'] == 'release':
|
|
|
|
lib_type_dir = 'release'
|
2016-10-30 18:57:40 +01:00
|
|
|
else: # release_debug, debug
|
2016-10-30 18:44:57 +01:00
|
|
|
lib_type_dir = 'debug'
|
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
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"))
|
2018-08-23 00:02:47 +02:00
|
|
|
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'
|
2018-09-28 13:29:52 +02:00
|
|
|
env_android.Command(out_dir + '/libc++_shared.so', stl_lib_path, Copy("$TARGET", "$SOURCE"))
|