prefer build.gradle with Android Plugin as source of package/version/code

These days, the location that overrides all the others is in the android{}
block of the build.gradle file that loads the com.android.application
plugin.  So this should be the preferred place to read these values.

test files GPL licensed: https://github.com/Integreight/1Sheeld-Android-App
This commit is contained in:
Hans-Christoph Steiner 2020-02-03 21:13:26 +01:00
parent d9722f4453
commit 83ffeb855f
17 changed files with 598 additions and 2 deletions

View file

@ -81,6 +81,7 @@ FDROID_PACKAGE_NAME_REGEX = re.compile(r'''^[a-f0-9]+$''', re.IGNORECASE)
STRICT_APPLICATION_ID_REGEX = re.compile(r'''(?:^[a-zA-Z]+(?:\d*[a-zA-Z_]*)*)(?:\.[a-zA-Z]+(?:\d*[a-zA-Z_]*)*)+$''')
VALID_APPLICATION_ID_REGEX = re.compile(r'''(?:^[a-z_]+(?:\d*[a-zA-Z_]*)*)(?:\.[a-z_]+(?:\d*[a-zA-Z_]*)*)*$''',
re.IGNORECASE)
ANDROID_PLUGIN_REGEX = re.compile(r'''\s*(:?apply plugin:|id)\(?\s*['"](android|com\.android\.application)['"]\s*\)?''')
MAX_VERSION_CODE = 0x7fffffff # Java's Integer.MAX_VALUE (2147483647)
@ -1421,6 +1422,7 @@ def parse_androidmanifests(paths, app):
if has_extension(path, 'gradle'):
with open(path, 'r') as f:
android_plugin_file = False
inside_flavour_group = 0
inside_required_flavour = 0
for line in f:
@ -1496,6 +1498,17 @@ def parse_androidmanifests(paths, app):
matches = vcsearch_g(line)
if matches:
vercode = matches.group(1)
if not android_plugin_file and ANDROID_PLUGIN_REGEX.match(line):
android_plugin_file = True
if android_plugin_file:
if package:
max_package = package
if version:
max_version = version
if vercode:
max_vercode = vercode
if max_package and max_version and max_vercode:
break
else:
try:
xml = parse_xml(path)

View file

@ -41,7 +41,6 @@ from .exception import FDroidException
SETTINGS_GRADLE = re.compile(r'settings\.gradle(?:\.kts)?')
GRADLE_SUBPROJECT = re.compile(r'''['"]:([^'"]+)['"]''')
ANDROID_PLUGIN = re.compile(r'''\s*(:?apply plugin:|id)\(?\s*['"](android|com\.android\.application)['"]\s*\)?''')
# Get the repo type and address from the given web page. The page is scanned
@ -197,7 +196,7 @@ def get_gradle_subdir(build_dir, paths):
line = fp.readline()
if not line:
break
if ANDROID_PLUGIN.match(line):
if common.ANDROID_PLUGIN_REGEX.match(line):
return os.path.relpath(os.path.dirname(f), build_dir)
if first_gradle_dir and first_gradle_dir != '.':
return first_gradle_dir