Build APK / build (push) Failing after 6s
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Patche le scaffold Android généré par `flutter create` :
|
|
- permissions (internet + auto-install APK)
|
|
- signature release depuis key.properties
|
|
- schéma de redirection OIDC (flutter_appauth)
|
|
Lancé dans la CI après `flutter create`. Idempotent."""
|
|
import os
|
|
import re
|
|
|
|
KSPW = os.environ["KSPW"]
|
|
ALIAS = os.environ["ALIAS"]
|
|
|
|
# 1) key.properties
|
|
with open("android/key.properties", "w") as f:
|
|
f.write(
|
|
f"storePassword={KSPW}\n"
|
|
f"keyPassword={KSPW}\n"
|
|
f"keyAlias={ALIAS}\n"
|
|
"storeFile=/app/gamemanager.keystore\n"
|
|
)
|
|
|
|
# 2) AndroidManifest : permissions
|
|
man = "android/app/src/main/AndroidManifest.xml"
|
|
s = open(man).read()
|
|
perms = (
|
|
'<uses-permission android:name="android.permission.INTERNET"/>\n'
|
|
' <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>\n'
|
|
)
|
|
if "REQUEST_INSTALL_PACKAGES" not in s:
|
|
s = s.replace("<application", perms + " <application", 1)
|
|
open(man, "w").write(s)
|
|
|
|
# 3) build.gradle : signature + schéma OIDC
|
|
gr = "android/app/build.gradle"
|
|
s = open(gr).read()
|
|
# ⚠️ Rien n'est autorisé AVANT le bloc plugins {} → on insère juste avant `android {`
|
|
if "keystoreProperties" not in s:
|
|
s = s.replace(
|
|
"android {",
|
|
'def keystoreProperties = new Properties()\n'
|
|
'def keystorePropertiesFile = rootProject.file("key.properties")\n'
|
|
'if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) }\n\n'
|
|
'android {',
|
|
1,
|
|
)
|
|
if "appAuthRedirectScheme" not in s:
|
|
s = s.replace(
|
|
"defaultConfig {",
|
|
'defaultConfig {\n manifestPlaceholders += [appAuthRedirectScheme: "nfteam.gamemanager"]',
|
|
1,
|
|
)
|
|
if "signingConfigs {" not in s:
|
|
s = re.sub(
|
|
r"(\n\s*buildTypes\s*\{)",
|
|
'\n signingConfigs {\n'
|
|
' release {\n'
|
|
' keyAlias keystoreProperties["keyAlias"]\n'
|
|
' keyPassword keystoreProperties["keyPassword"]\n'
|
|
' storeFile file(keystoreProperties["storeFile"])\n'
|
|
' storePassword keystoreProperties["storePassword"]\n'
|
|
' }\n }\n\\1',
|
|
s,
|
|
count=1,
|
|
)
|
|
s = s.replace("signingConfig signingConfigs.debug", "signingConfig signingConfigs.release")
|
|
open(gr, "w").write(s)
|
|
print("patch_android: OK")
|