Build APK / build (push) Successful in 2m28s
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
76 lines
3.0 KiB
Python
76 lines
3.0 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,
|
|
)
|
|
s = s.replace("signingConfig signingConfigs.debug", "signingConfig signingConfigs.release")
|
|
open(gr, "w").write(s)
|
|
print("patch_android: OK")
|