Add parameters to specify custom native build path and enable unity build in Android gradle builds (#1494)

* Add parameters to specify custom native build path and enable unity build in Android gradle builds

* Enable unity build for gradle to shorten the path to the generated object files which fixes build failures on Jenkins due to paths exceeding limit. This also speeds up builds.
This commit is contained in:
SJ
2021-06-22 15:31:52 -07:00
committed by GitHub
parent 37155fe0bf
commit cb2d64b205
3 changed files with 29 additions and 10 deletions
@@ -331,7 +331,7 @@ android_gradle_plugin={android_gradle_plugin_version}
NATIVE_CMAKE_SECTION_ANDROID_FORMAT = """
externalNativeBuild {{
cmake {{
buildStagingDirectory "."
buildStagingDirectory "{native_build_path}"
version "{cmake_version}"
path "{absolute_cmakelist_path}"
}}
@@ -447,8 +447,8 @@ class AndroidProjectGenerator(object):
def __init__(self, engine_root, build_dir, android_sdk_path, build_tool, android_sdk_platform, android_native_api_level, android_ndk,
project_path, third_party_path, cmake_version, override_cmake_path, override_gradle_path, gradle_version, gradle_plugin_version,
override_ninja_path, include_assets_in_apk, asset_mode, asset_type, signing_config, is_test_project=False,
overwrite_existing=True):
override_ninja_path, include_assets_in_apk, asset_mode, asset_type, signing_config, native_build_path, is_test_project=False,
overwrite_existing=True, unity_build_enabled=False):
"""
Initialize the object with all the required parameters needed to create an Android Project. The parameters should be verified before initializing this object
@@ -509,6 +509,8 @@ class AndroidProjectGenerator(object):
self.include_assets_in_apk = include_assets_in_apk
self.native_build_path = native_build_path
self.asset_mode = asset_mode
self.asset_type = asset_type
@@ -519,6 +521,8 @@ class AndroidProjectGenerator(object):
self.overwrite_existing = overwrite_existing
self.unity_build_enabled = unity_build_enabled
def execute(self):
"""
Execute the android project creation workflow
@@ -756,6 +760,9 @@ class AndroidProjectGenerator(object):
template_engine_root = common.normalize_path_for_settings(self.engine_root)
template_third_party_path = common.normalize_path_for_settings(self.third_party_path)
template_ndk_path = common.normalize_path_for_settings(os.path.join(self.android_sdk_path, self.android_ndk.location))
template_unity_build = 1 if self.unity_build_enabled else 0
native_build_path = pathlib.Path(self.native_build_path).resolve().as_posix() if self.native_build_path else '.'
gradle_build_env = dict()
@@ -766,7 +773,7 @@ class AndroidProjectGenerator(object):
gradle_build_env['TARGET_TYPE'] = 'application'
gradle_build_env['PROJECT_DEPENDENCIES'] = PROJECT_DEPENDENCIES_VALUE_FORMAT.format(dependencies='\n'.join(gradle_project_dependencies))
gradle_build_env['NATIVE_CMAKE_SECTION_ANDROID'] = NATIVE_CMAKE_SECTION_ANDROID_FORMAT.format(cmake_version=str(self.cmake_version), absolute_cmakelist_path=absolute_cmakelist_path)
gradle_build_env['NATIVE_CMAKE_SECTION_ANDROID'] = NATIVE_CMAKE_SECTION_ANDROID_FORMAT.format(cmake_version=str(self.cmake_version), native_build_path=native_build_path, absolute_cmakelist_path=absolute_cmakelist_path)
gradle_build_env['NATIVE_CMAKE_SECTION_DEFAULT_CONFIG'] = NATIVE_CMAKE_SECTION_DEFAULT_CONFIG_NDK_FORMAT_STR.format(abi=ANDROID_ARCH)
gradle_build_env['OVERRIDE_JAVA_SOURCESET'] = OVERRIDE_JAVA_SOURCESET_STR.format(absolute_azandroid_path=absolute_azandroid_path)
@@ -784,7 +791,8 @@ class AndroidProjectGenerator(object):
f'"-S{template_engine_root}"',
f'"-DCMAKE_BUILD_TYPE={native_config_lower}"',
f'"-DCMAKE_TOOLCHAIN_FILE={template_engine_root}/cmake/Platform/Android/Toolchain_Android.cmake"',
f'"-DLY_3RDPARTY_PATH={template_third_party_path}"']
f'"-DLY_3RDPARTY_PATH={template_third_party_path}"',
f'"-DLY_UNITY_BUILD={template_unity_build}"']
if not self.is_test_project:
cmake_argument_list.append(f'"-DLY_PROJECTS={pathlib.PurePath(self.project_path).as_posix()}"')