$ErrorActionPreference = "Stop" Write-Host "" Write-Host "=== YouTube Personal - Memoire 18.10.7 / Memoire Gradle-D8 ===" -ForegroundColor Cyan Write-Host "Projet : $PWD" Write-Host "" $root = (Get-Location).Path $gradleProps = Join-Path $root "android\gradle.properties" $rootGradle = Join-Path $root "android\build.gradle.kts" foreach ($path in @($gradleProps, $rootGradle)) { if (-not (Test-Path $path)) { throw "Fichier introuvable : $path" } } # Verifie que le bridge 18.10.6 est bien present avant de continuer. $gradleText = Get-Content $rootGradle -Raw if ($gradleText -notmatch 'YOUTUBE_PERSONAL_AGP9_KOTLIN_BRIDGE_18_10_6') { throw "Le bridge Kotlin 18.10.6 est absent. Applique d'abord le correctif 18.10.6." } Write-Host "[OK] Bridge Kotlin 18.10.6 detecte." -ForegroundColor Green $backup = "$gradleProps.before_memory_18_10_7" if (-not (Test-Path $backup)) { Copy-Item $gradleProps $backup Write-Host "[OK] Sauvegarde : $backup" -ForegroundColor Green } # Choisit une heap prudente en fonction de la RAM physique disponible. $totalGb = 0 try { $totalGb = [math]::Floor((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB) } catch { $totalGb = 16 } if ($totalGb -ge 24) { $heap = "8g" $meta = "1536m" $kotlinHeap = "2048m" } elseif ($totalGb -ge 16) { $heap = "6g" $meta = "1024m" $kotlinHeap = "1536m" } elseif ($totalGb -ge 12) { $heap = "4g" $meta = "768m" $kotlinHeap = "1024m" } else { $heap = "3g" $meta = "512m" $kotlinHeap = "768m" } Write-Host "[INFO] RAM detectee : environ $totalGb Go" -ForegroundColor DarkGray Write-Host "[INFO] Heap Gradle choisie : $heap" -ForegroundColor DarkGray $props = Get-Content $gradleProps -Raw function Set-GradleProperty { param([string]$Name, [string]$Value) $pattern = '(?m)^\s*' + [regex]::Escape($Name) + '\s*=.*$' $line = "$Name=$Value" if ($script:props -match $pattern) { $script:props = [regex]::Replace($script:props, $pattern, $line, 1) } else { if (-not $script:props.EndsWith("`n")) { $script:props += "`r`n" } $script:props += "$line`r`n" } } Write-Host "[1/5] Configuration memoire Gradle / Kotlin..." -ForegroundColor Yellow Set-GradleProperty "org.gradle.jvmargs" "-Xmx$heap -XX:MaxMetaspaceSize=$meta -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8" Set-GradleProperty "kotlin.daemon.jvmargs" "-Xmx$kotlinHeap -Dfile.encoding=UTF-8" Set-GradleProperty "org.gradle.parallel" "false" Set-GradleProperty "org.gradle.workers.max" "2" Set-GradleProperty "org.gradle.daemon" "true" # Conserve les deux proprietes requises par le bridge 18.10.6. Set-GradleProperty "android.builtInKotlin" "false" Set-GradleProperty "android.newDsl" "false" Set-Content -Path $gradleProps -Value $props -Encoding UTF8 Write-Host "[OK] org.gradle.jvmargs configure sur -Xmx$heap" -ForegroundColor Green Write-Host "[OK] org.gradle.workers.max=2" -ForegroundColor Green Write-Host "[OK] org.gradle.parallel=false" -ForegroundColor Green Write-Host "[2/5] Arret du programme et des anciens daemons Gradle..." -ForegroundColor Yellow Get-Process youtube_personal -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue Push-Location (Join-Path $root "android") try { & .\gradlew.bat --stop | Out-Host } catch { Write-Host "[INFO] Aucun daemon Gradle actif." -ForegroundColor DarkGray } Pop-Location Write-Host "[3/5] Nettoyage des sorties de build uniquement..." -ForegroundColor Yellow $buildDir = Join-Path $root "build" if (Test-Path $buildDir) { try { Remove-Item $buildDir -Recurse -Force -ErrorAction Stop Write-Host "[OK] build supprime." -ForegroundColor Green } catch { Write-Host "[ATTENTION] build partiellement verrouille; Gradle reconstruira ce qui est necessaire." -ForegroundColor Yellow } } Write-Host "[4/5] Resolution des dependances..." -ForegroundColor Yellow flutter pub get if ($LASTEXITCODE -ne 0) { throw "flutter pub get a echoue." } Write-Host "[5/5] Build Debug ARM64 de verification..." -ForegroundColor Yellow Write-Host " (ARM64 uniquement pour reduire fortement le pic memoire D8/CMake)" -ForegroundColor DarkGray flutter build apk --debug --target-platform android-arm64 if ($LASTEXITCODE -ne 0) { Write-Host "" Write-Host "Le correctif memoire est applique mais le build a encore echoue." -ForegroundColor Red Write-Host "Copie la nouvelle erreur a partir de 'FAILURE:' ou 'Error:'." -ForegroundColor Yellow exit 1 } $apk = Join-Path $root "build\app\outputs\flutter-apk\app-debug.apk" Write-Host "" Write-Host "[OK] Build Android Debug ARM64 reussi." -ForegroundColor Green if (Test-Path $apk) { Write-Host "APK Debug : $apk" -ForegroundColor Cyan } Write-Host "" Write-Host "Teste maintenant sur le smartphone :" -ForegroundColor Cyan Write-Host " flutter run -d f10778d8" Write-Host "" Write-Host "Puis APK Release ARM64 :" -ForegroundColor Cyan Write-Host " flutter build apk --release --target-platform android-arm64" Write-Host ""