From 318195c6fde02437fdc4c9a9f3cc474f1f16ba6e Mon Sep 17 00:00:00 2001 From: dahoud <41957584+DahoudG@users.noreply.github.com> Date: Sun, 12 Apr 2026 14:51:36 +0000 Subject: [PATCH] =?UTF-8?q?feat(dev):=20centraliser=20l'IP=20LAN=20dans=20?= =?UTF-8?q?android/local.properties=20=E2=80=94=20source=20unique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- android/app/build.gradle | 57 +++++++++++++++++++ .../main/res/xml/network_security_config.xml | 9 ++- lib/core/config/environment.dart | 10 +++- lib/core/config/local_config.dart | 4 ++ 4 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 lib/core/config/local_config.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index a20812f..c4cef3f 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -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 = """\ + + + + + + + + + + + ${devHost} + localhost + 10.0.2.2 + 127.0.0.1 + +""" + + 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 diff --git a/android/app/src/main/res/xml/network_security_config.xml b/android/app/src/main/res/xml/network_security_config.xml index f9213f7..9ba44fc 100644 --- a/android/app/src/main/res/xml/network_security_config.xml +++ b/android/app/src/main/res/xml/network_security_config.xml @@ -1,17 +1,16 @@ - + - - + - 192.168.1.9 + 192.168.1.13 localhost 10.0.2.2 127.0.0.1 - + \ No newline at end of file diff --git a/lib/core/config/environment.dart b/lib/core/config/environment.dart index 9f270d4..e74358a 100644 --- a/lib/core/config/environment.dart +++ b/lib/core/config/environment.dart @@ -1,8 +1,12 @@ +import 'local_config.dart'; + /// Environnements de déploiement de l'application enum Environment { dev, staging, prod } /// Configuration centralisée par environnement. /// Les URLs sont injectées via --dart-define=ENV=dev|staging|prod +/// L'IP dev est définie dans android/local.properties → dev.host +/// (propagée automatiquement vers ce fichier via build.gradle). class AppConfig { static late final Environment _environment; static late final String apiBaseUrl; @@ -26,15 +30,15 @@ class AppConfig { case Environment.dev: apiBaseUrl = const String.fromEnvironment( 'API_URL', - defaultValue: 'http://localhost:8085', + defaultValue: 'http://$kDevHost:8085', ); keycloakBaseUrl = const String.fromEnvironment( 'KEYCLOAK_URL', - defaultValue: 'http://localhost:8180', + defaultValue: 'http://$kDevHost:8180', ); wsBaseUrl = const String.fromEnvironment( 'WS_URL', - defaultValue: 'ws://localhost:8085', + defaultValue: 'ws://$kDevHost:8085', ); enableDebugMode = true; enableLogging = true; diff --git a/lib/core/config/local_config.dart b/lib/core/config/local_config.dart new file mode 100644 index 0000000..4a49238 --- /dev/null +++ b/lib/core/config/local_config.dart @@ -0,0 +1,4 @@ +// AUTO-GENERATED by build.gradle - DO NOT EDIT +// Edit android/local.properties (dev.host) instead. +// ignore_for_file: prefer_single_quotes +const String kDevHost = '192.168.1.13';