feat(dev): centraliser l'IP LAN dans android/local.properties — source unique
- build.gradle : tâche generateDevConfig qui propage dev.host vers network_security_config.xml et lib/core/config/local_config.dart à chaque build - environment.dart : import kDevHost depuis local_config.dart pour les URLs dev (apiBaseUrl, keycloakBaseUrl, wsBaseUrl) — plus de constante IP hardcodée - local_config.dart : fichier auto-généré (ne pas éditer directement) - network_security_config.xml : autorisation cleartext pour 192.168.1.13 Pour changer l'IP : modifier uniquement android/local.properties → dev.host
This commit is contained in:
@@ -5,6 +5,63 @@ plugins {
|
||||
id "dev.flutter.flutter-gradle-plugin"
|
||||
}
|
||||
|
||||
// ── Dev Host — source unique : android/local.properties → dev.host ───────────
|
||||
def localProps = new Properties()
|
||||
def localPropsFile = rootProject.file('local.properties')
|
||||
if (localPropsFile.exists()) localPropsFile.withInputStream { localProps.load(it) }
|
||||
def devHost = localProps.getProperty('dev.host', '10.0.2.2')
|
||||
|
||||
task generateDevConfig {
|
||||
description = 'Generates network_security_config.xml and local_config.dart from local.properties'
|
||||
group = 'UnionFlow'
|
||||
inputs.property('devHost', devHost)
|
||||
outputs.files(
|
||||
file("src/main/res/xml/network_security_config.xml"),
|
||||
rootProject.file("../lib/core/config/local_config.dart")
|
||||
)
|
||||
doLast {
|
||||
def xmlContent = """\
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<!-- Production: cleartext disabled by default -->
|
||||
<base-config cleartextTrafficPermitted="false">
|
||||
<trust-anchors>
|
||||
<certificates src="system"/>
|
||||
</trust-anchors>
|
||||
</base-config>
|
||||
<!-- Dev local - single source: android/local.properties -> dev.host -->
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="true">${devHost}</domain>
|
||||
<domain includeSubdomains="true">localhost</domain>
|
||||
<domain includeSubdomains="true">10.0.2.2</domain>
|
||||
<domain includeSubdomains="true">127.0.0.1</domain>
|
||||
</domain-config>
|
||||
</network-security-config>"""
|
||||
|
||||
def dartContent = """\
|
||||
// AUTO-GENERATED by build.gradle - DO NOT EDIT
|
||||
// Edit android/local.properties (dev.host) instead.
|
||||
// ignore_for_file: prefer_single_quotes
|
||||
const String kDevHost = '${devHost}';
|
||||
"""
|
||||
|
||||
// Write with explicit UTF-8 encoding (avoids Windows-1252 on French systems)
|
||||
file("src/main/res/xml/network_security_config.xml")
|
||||
.newWriter('UTF-8').withWriter { w -> w << xmlContent }
|
||||
rootProject.file("../lib/core/config/local_config.dart")
|
||||
.newWriter('UTF-8').withWriter { w -> w << dartContent }
|
||||
}
|
||||
}
|
||||
preBuild.dependsOn generateDevConfig
|
||||
|
||||
// local_config.dart is consumed by Flutter compile tasks — declare explicit dependency
|
||||
tasks.configureEach { task ->
|
||||
if (task.name.startsWith('compileFlutterBuild')) {
|
||||
task.dependsOn generateDevConfig
|
||||
}
|
||||
}
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
android {
|
||||
namespace = "dev.lions.unionflow_mobile_apps"
|
||||
compileSdk = 36
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<!-- Production : cleartext interdit par défaut -->
|
||||
<!-- Production: cleartext disabled by default -->
|
||||
<base-config cleartextTrafficPermitted="false">
|
||||
<trust-anchors>
|
||||
<certificates src="system"/>
|
||||
</trust-anchors>
|
||||
</base-config>
|
||||
|
||||
<!-- Exceptions pour le développement local uniquement -->
|
||||
<!-- Dev local - single source: android/local.properties -> dev.host -->
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="true">192.168.1.9</domain>
|
||||
<domain includeSubdomains="true">192.168.1.13</domain>
|
||||
<domain includeSubdomains="true">localhost</domain>
|
||||
<domain includeSubdomains="true">10.0.2.2</domain>
|
||||
<domain includeSubdomains="true">127.0.0.1</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
||||
</network-security-config>
|
||||
Reference in New Issue
Block a user