Skip to content

Commit 6446464

Browse files
graycreateclaude
andcommitted
fix: properly look for universal APKs in Google Play API response
- First check generatedUniversalApk field as per API documentation - Fallback to base module in generatedSplitApks if needed - Simplified variant selection logic - This should resolve HTTP 204 errors by using correct APK structure 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent d838b78 commit 6446464

File tree

1 file changed

+40
-50
lines changed

1 file changed

+40
-50
lines changed

.github/workflows/release.yml

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -462,66 +462,58 @@ jobs:
462462
print(f" {key}: {value}")
463463
print()
464464
465-
# Find universal APK in generatedSplitApks (based on API debug output)
465+
# Find universal APK using the correct API structure
466466
download_id = None
467467
universal_apk = None
468468
469+
# First, try to find a universal APK in generatedUniversalApk
469470
for apk in result['generatedApks']:
470-
if 'generatedSplitApks' in apk:
471-
split_apks = apk['generatedSplitApks']
472-
print(f"Found {len(split_apks)} split APKs")
473-
474-
# Look for the base/universal APK - try variantId=2 first since variantId=1 consistently fails
475-
# Print all base modules for debugging
476-
base_candidates = []
477-
for split_apk in split_apks:
478-
if split_apk.get('moduleName') == 'base':
479-
base_candidates.append(split_apk)
480-
print(f"Base APK: variantId={split_apk.get('variantId')}, splitId={split_apk.get('splitId', 'None')}")
481-
482-
# Strategy 1: Try variantId=2 first (most likely to work based on observations)
483-
for split_apk in split_apks:
484-
if (split_apk.get('moduleName') == 'base' and
485-
split_apk.get('variantId') == 2 and
486-
'splitId' not in split_apk):
487-
download_id = split_apk.get('downloadId')
488-
universal_apk = split_apk
489-
print(f"Found universal APK (variantId=2): {universal_apk}")
490-
break
491-
492-
# Strategy 2: If variantId=2 not found, try variantId=3
493-
if not download_id:
471+
if 'generatedUniversalApk' in apk:
472+
universal_apk = apk['generatedUniversalApk']
473+
download_id = universal_apk.get('downloadId')
474+
print(f"Found universal APK: {universal_apk}")
475+
break
476+
477+
# Fallback: Look for base module in split APKs if no universal APK found
478+
if not download_id:
479+
print("No generatedUniversalApk found, trying split APKs...")
480+
for apk in result['generatedApks']:
481+
if 'generatedSplitApks' in apk:
482+
split_apks = apk['generatedSplitApks']
483+
print(f"Found {len(split_apks)} split APKs")
484+
485+
# Print all base modules for debugging
486+
base_candidates = []
494487
for split_apk in split_apks:
495-
if (split_apk.get('moduleName') == 'base' and
496-
split_apk.get('variantId') == 3 and
497-
'splitId' not in split_apk):
498-
download_id = split_apk.get('downloadId')
499-
universal_apk = split_apk
500-
print(f"Found universal APK (variantId=3): {universal_apk}")
501-
break
502-
503-
# Strategy 3: Try variantId=1 as last resort (known to fail)
504-
if not download_id:
488+
if split_apk.get('moduleName') == 'base':
489+
base_candidates.append(split_apk)
490+
print(f"Base APK: variantId={split_apk.get('variantId')}, splitId={split_apk.get('splitId', 'None')}")
491+
492+
# Try variantId=2 first (based on previous observations)
505493
for split_apk in split_apks:
506494
if (split_apk.get('moduleName') == 'base' and
507-
split_apk.get('variantId') == 1 and
495+
split_apk.get('variantId') == 2 and
508496
'splitId' not in split_apk):
509497
download_id = split_apk.get('downloadId')
510498
universal_apk = split_apk
511-
print(f"Found universal APK (variantId=1 - last resort): {universal_apk}")
499+
print(f"Found base APK (variantId=2): {universal_apk}")
512500
break
513-
514-
# Strategy 4: Fallback to first base module
515-
if not download_id and base_candidates:
516-
universal_apk = base_candidates[0]
517-
download_id = universal_apk.get('downloadId')
518-
print(f"Using first base module as fallback: {universal_apk}")
519-
520-
if download_id:
521-
break
501+
502+
# Try other variants if variantId=2 not found
503+
if not download_id:
504+
for split_apk in split_apks:
505+
if (split_apk.get('moduleName') == 'base' and
506+
'splitId' not in split_apk):
507+
download_id = split_apk.get('downloadId')
508+
universal_apk = split_apk
509+
print(f"Found base APK (variantId={split_apk.get('variantId')}): {universal_apk}")
510+
break
511+
512+
if download_id:
513+
break
522514
523515
if not download_id:
524-
print("Universal APK not found in generatedSplitApks")
516+
print("No universal or base APK found")
525517
print("Available APK structure:")
526518
print(json.dumps(result['generatedApks'], indent=2))
527519
return False
@@ -530,9 +522,7 @@ jobs:
530522
531523
# Step 2: Download the APK using the downloadId
532524
print("Downloading APK binary...")
533-
534-
# Execute the download request to get the media content
535-
download_request = service.generatedapks().download_media(
525+
download_request = service.generatedapks().download(
536526
packageName=package_name,
537527
versionCode=version_code,
538528
downloadId=download_id

0 commit comments

Comments
 (0)