Files
unionflow-server-impl-quarkus/unionflow-mobile-apps/fix-gradle-build.ps1
2025-08-20 21:00:35 +00:00

116 lines
4.5 KiB
PowerShell

#!/usr/bin/env pwsh
# Script pour résoudre les problèmes de build Gradle Flutter
Write-Host "🔧 Résolution des problèmes de build Flutter/Gradle..." -ForegroundColor Cyan
# 1. Nettoyer le cache Flutter
Write-Host "`n📦 Nettoyage du cache Flutter..." -ForegroundColor Yellow
flutter clean
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Erreur lors du nettoyage Flutter" -ForegroundColor Red
}
# 2. Nettoyer le cache Gradle
Write-Host "`n📦 Nettoyage du cache Gradle..." -ForegroundColor Yellow
Set-Location android
if (Test-Path "gradlew.bat") {
./gradlew.bat clean
} else {
./gradlew clean
}
Set-Location ..
# 3. Supprimer les dossiers de build
Write-Host "`n🗑️ Suppression des dossiers de build..." -ForegroundColor Yellow
$foldersToDelete = @(
"build",
"android/build",
"android/app/build",
"android/.gradle",
".dart_tool"
)
foreach ($folder in $foldersToDelete) {
if (Test-Path $folder) {
Write-Host " Suppression de $folder"
Remove-Item -Path $folder -Recurse -Force -ErrorAction SilentlyContinue
}
}
# 4. Récupérer les packages Flutter
Write-Host "`n📥 Récupération des packages Flutter..." -ForegroundColor Yellow
flutter pub get
# 5. Vérifier la connexion réseau
Write-Host "`n🌐 Test de connexion réseau..." -ForegroundColor Yellow
$testConnection = Test-NetConnection -ComputerName "services.gradle.org" -Port 443 -InformationLevel Quiet
if ($testConnection) {
Write-Host "✅ Connexion à services.gradle.org OK" -ForegroundColor Green
} else {
Write-Host "❌ Impossible de se connecter à services.gradle.org" -ForegroundColor Red
Write-Host " Vérifiez votre connexion internet ou les paramètres proxy" -ForegroundColor Yellow
# Afficher les variables d'environnement proxy si elles existent
if ($env:HTTP_PROXY -or $env:HTTPS_PROXY) {
Write-Host "`n📋 Variables proxy détectées:" -ForegroundColor Yellow
if ($env:HTTP_PROXY) { Write-Host " HTTP_PROXY: $env:HTTP_PROXY" }
if ($env:HTTPS_PROXY) { Write-Host " HTTPS_PROXY: $env:HTTPS_PROXY" }
}
}
# 6. Télécharger Gradle manuellement si nécessaire
Write-Host "`n📥 Vérification de Gradle..." -ForegroundColor Yellow
$gradleVersion = "8.3"
$gradleHome = "$env:USERPROFILE\.gradle\wrapper\dists\gradle-$gradleVersion-all"
if (-not (Test-Path $gradleHome)) {
Write-Host " Gradle $gradleVersion n'est pas installé localement" -ForegroundColor Yellow
Write-Host " Tentative de téléchargement manuel..." -ForegroundColor Cyan
# Créer le dossier si nécessaire
$wrapperDir = "$env:USERPROFILE\.gradle\wrapper\dists"
if (-not (Test-Path $wrapperDir)) {
New-Item -Path $wrapperDir -ItemType Directory -Force | Out-Null
}
# URL de téléchargement
$gradleUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
$gradleZip = "$env:TEMP\gradle-$gradleVersion-all.zip"
try {
Write-Host " Téléchargement depuis $gradleUrl..."
Invoke-WebRequest -Uri $gradleUrl -OutFile $gradleZip -UseBasicParsing
Write-Host "✅ Téléchargement réussi" -ForegroundColor Green
} catch {
Write-Host "❌ Échec du téléchargement: $_" -ForegroundColor Red
Write-Host "`n💡 Solutions alternatives:" -ForegroundColor Yellow
Write-Host " 1. Téléchargez manuellement: $gradleUrl"
Write-Host " 2. Placez le fichier dans: $env:TEMP"
Write-Host " 3. Relancez ce script"
}
} else {
Write-Host "✅ Gradle $gradleVersion trouvé localement" -ForegroundColor Green
}
# 7. Tester le build
Write-Host "`n🚀 Test du build Android..." -ForegroundColor Cyan
$response = Read-Host "Voulez-vous lancer le build maintenant? (O/N)"
if ($response -eq 'O' -or $response -eq 'o') {
flutter build apk --debug
if ($LASTEXITCODE -eq 0) {
Write-Host "`n✅ Build réussi!" -ForegroundColor Green
} else {
Write-Host "`n❌ Le build a échoué" -ForegroundColor Red
Write-Host "`n💡 Essayez ces commandes manuellement:" -ForegroundColor Yellow
Write-Host " 1. cd android"
Write-Host " 2. ./gradlew.bat assembleDebug --offline"
Write-Host " (mode offline si problème réseau)"
}
}
Write-Host "`n📝 Rapport final:" -ForegroundColor Cyan
Write-Host " - Cache Flutter nettoyé"
Write-Host " - Cache Gradle nettoyé"
Write-Host " - Packages récupérés"
Write-Host " - Timeout réseau augmenté dans gradle.properties"
Write-Host "`n✨ Script terminé!" -ForegroundColor Green