aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-11-11 14:32:18 +0100
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-11-12 10:01:15 +0100
commitbfe1814b767b71ffc3854038ec1d2961e258ae01 (patch)
tree8e3896d988da1101dbe5a847c9963bd25919d31f
parent16b668274c279730cf0e0d2ec2656e72c539c749 (diff)
Android Deployment: Fix bug with non provided ndk_path and sdk_path
- Updates de524f258c3980814fbc724ed61816894403fa3f. Basically the download part should be outside the 'if download_only' block because otherwise the ndk_path and sdk_path would remain None when ndk_path and sdk_path are not provided via command line arguments. - Adds some error handling to the NDK and Command Line Tools download functions. Pick-to: 6.8 Task-number: PYSIDE-1612 Change-Id: I545f148caf1c185a1a2cbeeebd5aad3a5359d52b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--tools/cross_compile_android/android_utilities.py67
-rw-r--r--tools/cross_compile_android/main.py24
2 files changed, 51 insertions, 40 deletions
diff --git a/tools/cross_compile_android/android_utilities.py b/tools/cross_compile_android/android_utilities.py
index 0650bdc41..45dd874f5 100644
--- a/tools/cross_compile_android/android_utilities.py
+++ b/tools/cross_compile_android/android_utilities.py
@@ -153,26 +153,31 @@ def download_android_ndk(ndk_path: Path):
if ndk_version_path.exists():
print(f"NDK path found in {str(ndk_version_path)}")
else:
- ndk_path.mkdir(parents=True, exist_ok=True)
- url = (f"https://dl.google.com/android/repository"
- f"/android-ndk-r{ANDROID_NDK_VERSION}-{sys.platform}.{ndk_extension}")
-
- print(f"Downloading Android Ndk version r{ANDROID_NDK_VERSION}")
- _download(url=url, destination=ndk_zip_path)
-
- print("Unpacking Android Ndk")
- if sys.platform == "darwin":
- extract_dmg(file=(ndk_path
- / f"android-ndk-r{ANDROID_NDK_VERSION}-{sys.platform}.{ndk_extension}"
- ),
- destination=ndk_path)
- ndk_version_path = (ndk_version_path
- / f"AndroidNDK{ANDROID_NDK_VERSION_NUMBER_SUFFIX}.app/Contents/NDK")
- else:
- extract_zip(file=(ndk_path
- / f"android-ndk-r{ANDROID_NDK_VERSION}-{sys.platform}.{ndk_extension}"
- ),
- destination=ndk_path)
+ try:
+ ndk_path.mkdir(parents=True, exist_ok=True)
+ url = (f"https://dl.google.com/android/repository"
+ f"/android-ndk-r{ANDROID_NDK_VERSION}-{sys.platform}.{ndk_extension}")
+
+ print(f"Downloading Android Ndk version r{ANDROID_NDK_VERSION}")
+ _download(url=url, destination=ndk_zip_path)
+
+ print("Unpacking Android Ndk")
+ if sys.platform == "darwin":
+ extract_dmg(file=(ndk_path
+ / f"android-ndk-r{ANDROID_NDK_VERSION}-{sys.platform}.{ndk_extension}"),
+ destination=ndk_path)
+ ndk_version_path = (ndk_version_path
+ / (f"AndroidNDK{ANDROID_NDK_VERSION_NUMBER_SUFFIX}.app"
+ "/Contents/NDK"))
+ else:
+ extract_zip(file=(ndk_path
+ / f"android-ndk-r{ANDROID_NDK_VERSION}-{sys.platform}.{ndk_extension}"),
+ destination=ndk_path)
+ except Exception as e:
+ print(f"Error occurred while downloading and unpacking Android NDK: {e}")
+ if ndk_path.exists():
+ shutil.rmtree(ndk_path)
+ sys.exit(1)
return ndk_version_path
@@ -192,14 +197,20 @@ def download_android_commandlinetools(android_sdk_dir: Path):
if cltools_path.exists():
print(f"Command-line tools found in {str(cltools_path)}")
else:
- android_sdk_dir.mkdir(parents=True, exist_ok=True)
-
- print("Download Android Command Line Tools: "
- f"commandlinetools-{sys.platform}-{DEFAULT_SDK_TAG}_latest.zip")
- _download(url=url, destination=cltools_zip_path)
-
- print("Unpacking Android Command Line Tools")
- extract_zip(file=cltools_zip_path, destination=android_sdk_dir)
+ try:
+ android_sdk_dir.mkdir(parents=True, exist_ok=True)
+
+ print("Download Android Command Line Tools: "
+ f"commandlinetools-{sys.platform}-{DEFAULT_SDK_TAG}_latest.zip")
+ _download(url=url, destination=cltools_zip_path)
+
+ print("Unpacking Android Command Line Tools")
+ extract_zip(file=cltools_zip_path, destination=android_sdk_dir)
+ except Exception as e:
+ print(f"Error occurred while downloading and unpacking Android Command Line Tools: {e}")
+ if android_sdk_dir.exists():
+ shutil.rmtree(android_sdk_dir)
+ sys.exit(1)
return android_sdk_dir
diff --git a/tools/cross_compile_android/main.py b/tools/cross_compile_android/main.py
index bf35c1473..2884793ca 100644
--- a/tools/cross_compile_android/main.py
+++ b/tools/cross_compile_android/main.py
@@ -185,19 +185,19 @@ if __name__ == "__main__":
if toolchain_path.is_file():
toolchain_path.unlink()
- if download_only:
- if not ndk_path:
- # Download android ndk
- ndk_path = download_android_ndk(pyside6_deploy_cache)
-
- if not sdk_path:
- # download and unzip command-line tools
- sdk_path = download_android_commandlinetools(pyside6_deploy_cache)
- # install and update required android packages
- install_android_packages(android_sdk_dir=sdk_path, android_api=api_level,
- dry_run=dry_run, accept_license=auto_accept_license,
- skip_update=skip_update)
+ if not ndk_path:
+ # Download android ndk
+ ndk_path = download_android_ndk(pyside6_deploy_cache)
+
+ if not sdk_path:
+ # download and unzip command-line tools
+ sdk_path = download_android_commandlinetools(pyside6_deploy_cache)
+ # install and update required android packages
+ install_android_packages(android_sdk_dir=sdk_path, android_api=api_level,
+ dry_run=dry_run, accept_license=auto_accept_license,
+ skip_update=skip_update)
+ if download_only:
print(f"Android NDK and SDK downloaded successfully into {pyside6_deploy_cache}")
sys.exit(0)