qt-android-runner.py: handle all possible Gradle namespace formats

Handle all supported formats to set the namespace under build.gradle,
this include cases where the name is using single or double quotes,
and when using an equal sign or space separator.

Fixes: QTBUG-138864
Pick-to: 6.8
Change-Id: Ib1381525ef85ab112cde5f4086065cf2af72b670
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit e21b5c140e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit ccfd1155b5)
This commit is contained in:
Assam Boudjelthia 2025-08-01 15:44:28 +03:00 committed by Qt Cherry-pick Bot
parent 2b85ac86ae
commit c57362efea
1 changed files with 11 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import base64
import time import time
import signal import signal
import argparse import argparse
import re
def status(msg): def status(msg):
print(f"\n-- {msg}") print(f"\n-- {msg}")
@ -103,10 +104,16 @@ def get_package_name(build_path):
with open(gradle_file) as f: with open(gradle_file) as f:
for line in f: for line in f:
if line.strip().startswith("namespace"): if line.strip().startswith("namespace"):
potentialPackageName = line.split('=')[1].strip().strip('"') # Match the following cases:
if (potentialPackageName == "androidPackageName"): # namespace "org.qtproject.example.app"
break; # namespace 'org.qtproject.example.app'
return potentialPackageName # namespace = "org.qtproject.example.app"
# namespace = 'org.qtproject.example.app'
match = re.search(r"namespace\s*=?\s*['\"]([^'\"]+)['\"]", line)
if match:
potentialPackageName = match.group(1)
if (potentialPackageName != "androidPackageName"):
return potentialPackageName
properties_file = os.path.join(args.build_path, "gradle.properties") properties_file = os.path.join(args.build_path, "gradle.properties")
if os.path.isfile(properties_file): if os.path.isfile(properties_file):