Build APK / build (push) Successful in 2m28s
- patch_android.py: gère 'signingConfig = signingConfigs.debug' (Flutter 3.24 utilise le '='), sans quoi le build restait signé en clé debug éphémère → signature différente à chaque run → 'conflit' à l'install de MAJ. Échoue désormais le build si la ligne n'est pas patchée (garde-fou). - update_service: télécharge l'APK in-app + lance l'installeur (open_filex), fallback navigateur ; barre de progression dans l'écran serveurs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
84 lines
3.5 KiB
Python
84 lines
3.5 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
|
|
- CallbackActivity flutter_web_auth_2 (retour OIDC, schéma nfteam.gamemanager)
|
|
Lancé dans la CI après `flutter create`. Idempotent."""
|
|
import os
|
|
import re
|
|
|
|
KSPW = os.environ["KSPW"]
|
|
ALIAS = os.environ["ALIAS"]
|
|
KEYSTORE_PATH = os.environ.get("KEYSTORE_PATH", os.path.abspath("gamemanager.keystore"))
|
|
|
|
# 1) key.properties (chemin absolu du keystore)
|
|
with open("android/key.properties", "w") as f:
|
|
f.write(
|
|
f"storePassword={KSPW}\n"
|
|
f"keyPassword={KSPW}\n"
|
|
f"keyAlias={ALIAS}\n"
|
|
f"storeFile={KEYSTORE_PATH}\n"
|
|
)
|
|
|
|
# 2) AndroidManifest : permissions + CallbackActivity OIDC
|
|
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)
|
|
callback = (
|
|
' <activity android:name="com.linusu.flutter_web_auth_2.CallbackActivity" '
|
|
'android:exported="true">\n'
|
|
' <intent-filter android:label="flutter_web_auth_2">\n'
|
|
' <action android:name="android.intent.action.VIEW"/>\n'
|
|
' <category android:name="android.intent.category.DEFAULT"/>\n'
|
|
' <category android:name="android.intent.category.BROWSABLE"/>\n'
|
|
' <data android:scheme="nfteam.gamemanager"/>\n'
|
|
' </intent-filter>\n'
|
|
' </activity>\n'
|
|
)
|
|
if "flutter_web_auth_2.CallbackActivity" not in s:
|
|
s = s.replace("</application>", callback + " </application>", 1)
|
|
open(man, "w").write(s)
|
|
|
|
# 3) build.gradle : signature release
|
|
gr = "android/app/build.gradle"
|
|
s = open(gr).read()
|
|
# ⚠️ Rien avant plugins {} → insérer 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 "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,
|
|
)
|
|
# Flutter 3.24 génère `signingConfig = signingConfigs.debug` (AVEC `=`). On gère
|
|
# les deux formes pour ne jamais laisser le build release signé en clé debug
|
|
# (sinon signature différente à chaque run CI → « conflit » à l'install de MAJ).
|
|
before = s
|
|
s = s.replace("signingConfig = signingConfigs.debug", "signingConfig = signingConfigs.release")
|
|
s = s.replace("signingConfig signingConfigs.debug", "signingConfig signingConfigs.release")
|
|
if s == before:
|
|
raise SystemExit("patch_android: ERREUR — ligne 'signingConfig ... debug' introuvable, "
|
|
"signature release NON appliquée (build annulé)")
|
|
open(gr, "w").write(s)
|
|
print("patch_android: OK (signature release appliquee)")
|