diff --git a/fdroidserver/index.py b/fdroidserver/index.py
index 2bb966b7..61552138 100644
--- a/fdroidserver/index.py
+++ b/fdroidserver/index.py
@@ -213,6 +213,16 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
if packageName not in apps:
logging.info(_('Ignoring package without metadata: ') + package['apkName'])
continue
+ if not package.get('versionName'):
+ app = apps[packageName]
+ versionCodeStr = str(package['versionCode']) # TODO build.versionCode should be int!
+ for build in app['builds']:
+ if build['versionCode'] == versionCodeStr:
+ versionName = build.get('versionName')
+ logging.info(_('Overriding blank versionName in {apkfilename} from metadata: {version}')
+ .format(apkfilename=package['apkName'], version=versionName))
+ package['versionName'] = versionName
+ break
if packageName in output_packages:
packagelist = output_packages[packageName]
else:
@@ -479,7 +489,17 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
apkel = doc.createElement("package")
apel.appendChild(apkel)
- addElement('version', apk['versionName'], doc, apkel)
+
+ versionName = apk.get('versionName')
+ if not versionName:
+ versionCodeStr = str(apk['versionCode']) # TODO build.versionCode should be int!
+ for build in app.builds:
+ if build['versionCode'] == versionCodeStr and 'versionName' in build:
+ versionName = build['versionName']
+ break
+ if versionName:
+ addElement('version', versionName, doc, apkel)
+
addElement('versioncode', str(apk['versionCode']), doc, apkel)
addElement('apkname', apk['apkName'], doc, apkel)
addElementIfInApk('srcname', apk, 'srcname', doc, apkel)
diff --git a/fdroidserver/update.py b/fdroidserver/update.py
index d7f21e4b..2a31e8f1 100644
--- a/fdroidserver/update.py
+++ b/fdroidserver/update.py
@@ -1208,13 +1208,18 @@ def scan_apk_androguard(apk, apkfile):
apk['packageName'] = apkobject.get_package()
apk['versionCode'] = int(apkobject.get_androidversion_code())
- apk['versionName'] = apkobject.get_androidversion_name()
- if apk['versionName'][0] == "@":
- version_id = int(apk['versionName'].replace("@", "0x"), 16)
- version_id = arsc.get_id(apk['packageName'], version_id)[1]
- apk['versionName'] = arsc.get_string(apk['packageName'], version_id)[1]
apk['name'] = apkobject.get_app_name()
+ versionName = apkobject.get_androidversion_name()
+ if versionName:
+ apk['versionName'] = versionName
+ try: # can be a literal value or a resId
+ res_id = int(versionName.replace("@", "0x"), 16)
+ res_id = arsc.get_id(apk['packageName'], res_id)[1]
+ apk['versionName'] = arsc.get_string(apk['packageName'], res_id)[1]
+ except ValueError:
+ pass
+
if apkobject.get_max_sdk_version() is not None:
apk['maxSdkVersion'] = apkobject.get_max_sdk_version()
if apkobject.get_min_sdk_version() is not None:
diff --git a/tests/repo/duplicate.permisssions_9999999.apk b/tests/repo/duplicate.permisssions_9999999.apk
index ea440c5e..217b8731 100644
Binary files a/tests/repo/duplicate.permisssions_9999999.apk and b/tests/repo/duplicate.permisssions_9999999.apk differ
diff --git a/tests/repo/index-v1.json b/tests/repo/index-v1.json
index 90d586ce..cda10cf2 100644
--- a/tests/repo/index-v1.json
+++ b/tests/repo/index-v1.json
@@ -288,13 +288,13 @@
{
"added": 1513900800000,
"apkName": "duplicate.permisssions_9999999.apk",
- "hash": "3d5db5f1ee6fd1d5d9e3c97cc9139b447f538bacd9907f648ba96cfd0848321d",
+ "hash": "8367857fe75f85321ce2c344b34804d0bc193707f6ba03710d025d9030803434",
"hashType": "sha256",
"minSdkVersion": "18",
"packageName": "duplicate.permisssions",
"sig": "056c9f1554c40ba59a2103009c82b420",
"signer": "659e1fd284549f70d13fb02c620100e27eeea3420558cce62b0f5d4cf2b77d84",
- "size": 27507,
+ "size": 27446,
"targetSdkVersion": "27",
"uses-permission": [
[
@@ -336,8 +336,7 @@
null
]
],
- "versionCode": 9999999,
- "versionName": "0.3-7-gb817ac8"
+ "versionCode": 9999999
}
],
"fake.ota.update": [
diff --git a/tests/repo/index.xml b/tests/repo/index.xml
index 60136572..ef6988de 100644
--- a/tests/repo/index.xml
+++ b/tests/repo/index.xml
@@ -25,11 +25,10 @@
9999999
- 0.3-7-gb817ac8
9999999
duplicate.permisssions_9999999.apk
- 3d5db5f1ee6fd1d5d9e3c97cc9139b447f538bacd9907f648ba96cfd0848321d
- 27507
+ 8367857fe75f85321ce2c344b34804d0bc193707f6ba03710d025d9030803434
+ 27446
18
27
2017-12-22