MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Tools / main

Function main

scripts/android.py:103–196  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

101#
102# As a result CMake will need to be run multiple times to create a complete test APK that can be run on any Android device.
103def main():
104 configs = ['Release', 'Debug']
105
106 parser = argparse.ArgumentParser()
107 parser.add_argument('--config', type=str, choices=configs, default=configs[0])
108 parser.add_argument('--app-abi', dest='android_abi', type=str, default="arm64-v8a")
109 parser.add_argument('--app-stl', dest='android_stl', type=str, choices=["c++_static", "c++_shared"], default="c++_static")
110 parser.add_argument('--apk', action='store_true', help='Generate an APK as a post build step.')
111 parser.add_argument('--clean', action='store_true', help='Cleans CMake build artifacts')
112 args = parser.parse_args()
113
114 cmake_config = args.config
115 android_abis = args.android_abi.split(" ")
116 android_stl = args.android_stl
117 create_apk = args.apk
118 clean = args.clean
119
120 if "ANDROID_NDK_HOME" not in os.environ:
121 print("Cannot find ANDROID_NDK_HOME!")
122 sys.exit(1)
123
124 android_ndk_home = os.environ.get('ANDROID_NDK_HOME')
125 android_toolchain = f'{android_ndk_home}/build/cmake/android.toolchain.cmake'
126
127 # The only tool we require for building is CMake/Ninja
128 required_cli_tools = ['cmake', 'ninja']
129
130 # If we are building an APK we need a few more tools.
131 if create_apk:
132 if "ANDROID_SDK_ROOT" not in os.environ:
133 print("Cannot find ANDROID_SDK_ROOT!")
134 sys.exit(1)
135
136 android_sdk_root = os.environ.get('ANDROID_SDK_ROOT')
137 print(f"ANDROID_SDK_ROOT = {android_sdk_root}")
138 required_cli_tools += ['aapt', 'zipalign', 'keytool', 'apksigner']
139
140 print(f"ANDROID_NDK_HOME = {android_ndk_home}")
141 print(f"Build configured for {cmake_config} | {android_stl} | {android_abis} | APK {create_apk}")
142
143 if not os.path.isfile(android_toolchain):
144 print(f'Unable to find android.toolchain.cmake at {android_toolchain}')
145 exit(-1)
146
147 for tool in required_cli_tools:
148 path = shutil.which(tool)
149 if path is None:
150 print(f"Unable to find {tool}!")
151 exit(-1)
152
153 print(f"Using {tool} : {path}")
154
155 cmake_install_dir = RepoRelative('build-android/libs')
156
157 # Delete install directory since it could contain files from old runs
158 if os.path.isdir(cmake_install_dir):
159 print("Cleaning CMake install")
160 shutil.rmtree(cmake_install_dir)

Callers 1

android.pyFile · 0.70

Calls 3

generate_apkFunction · 0.85
RepoRelativeFunction · 0.70
RunShellCmdFunction · 0.70

Tested by

no test coverage detected