$ErrorActionPreference = "Stop" Write-Host "" Write-Host "=== YouTube Personal - Memoire 18.10.6 / Bridge Kotlin AGP 9 ===" -ForegroundColor Cyan Write-Host "Projet : $PWD" Write-Host "" $root = (Get-Location).Path $pubspec = Join-Path $root "pubspec.yaml" $gradleProps = Join-Path $root "android\gradle.properties" $rootGradle = Join-Path $root "android\build.gradle.kts" foreach ($path in @($pubspec, $gradleProps, $rootGradle)) { if (-not (Test-Path $path)) { throw "Fichier introuvable : $path" } } function Backup-Once([string]$Path, [string]$Suffix) { $backup = "$Path.$Suffix" if (-not (Test-Path $backup)) { Copy-Item $Path $backup Write-Host "[OK] Sauvegarde : $backup" -ForegroundColor Green } } Backup-Once $pubspec "before_memory_18_10_6" Backup-Once $gradleProps "before_memory_18_10_6" Backup-Once $rootGradle "before_memory_18_10_6" if (Test-Path (Join-Path $root "pubspec.lock")) { Backup-Once (Join-Path $root "pubspec.lock") "before_memory_18_10_6" } Write-Host "[1/6] Verification des dependances stables..." -ForegroundColor Yellow $content = Get-Content $pubspec -Raw function Set-DependencyLine { param([string]$Name, [string]$Version) $pattern = "(?m)^(\s*)" + [regex]::Escape($Name) + "\s*:\s*.*$" if ($script:content -match $pattern) { $script:content = [regex]::Replace( $script:content, $pattern, '${1}' + $Name + ': ' + $Version, 1 ) } else { $anchor = '(?m)^dependencies\s*:\s*$' if ($script:content -notmatch $anchor) { throw "Section dependencies introuvable dans pubspec.yaml." } $script:content = [regex]::Replace( $script:content, $anchor, "dependencies:`r`n $Name`: $Version", 1 ) } } # file_picker reste supprime. On conserve la pile memoire 18.10.3+. $content = [regex]::Replace($content, '(?m)^\s*file_picker\s*:\s*.*(?:\r?\n)?', '') Set-DependencyLine "wakelock_plus" "1.3.3" Set-DependencyLine "package_info_plus" "8.3.1" Set-DependencyLine "file_selector" "1.1.0" Set-DependencyLine "file_saver" "0.3.1" Set-Content -Path $pubspec -Value $content -Encoding UTF8 Write-Host "[OK] wakelock_plus = 1.3.3" -ForegroundColor Green Write-Host "[OK] package_info_plus = 8.3.1" -ForegroundColor Green Write-Host "[OK] file_selector = 1.1.0" -ForegroundColor Green Write-Host "[OK] file_saver = 0.3.1" -ForegroundColor Green Write-Host "[2/6] Activation explicite du mode Kotlin legacy compatible AGP 9..." -ForegroundColor Yellow $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" } } # Flutter 3.44 utilise ce mode comme pont temporaire pour les plugins KGP. Set-GradleProperty "android.builtInKotlin" "false" Set-GradleProperty "android.newDsl" "false" Set-Content -Path $gradleProps -Value $props -Encoding UTF8 Write-Host "[OK] android.builtInKotlin=false" -ForegroundColor Green Write-Host "[OK] android.newDsl=false" -ForegroundColor Green Write-Host "[3/6] Ajout du bridge Kotlin aux plugins qui perdaient leurs classes..." -ForegroundColor Yellow $gradle = Get-Content $rootGradle -Raw $beginMarker = "// BEGIN YOUTUBE_PERSONAL_AGP9_KOTLIN_BRIDGE_18_10_6" $endMarker = "// END YOUTUBE_PERSONAL_AGP9_KOTLIN_BRIDGE_18_10_6" # Retire une ancienne occurrence du meme bridge s'il y en a une. $markerPattern = '(?ms)^\s*// BEGIN YOUTUBE_PERSONAL_AGP9_KOTLIN_BRIDGE_18_10_6.*?// END YOUTUBE_PERSONAL_AGP9_KOTLIN_BRIDGE_18_10_6\s*' $gradle = [regex]::Replace($gradle, $markerPattern, '') $bridge = @' // BEGIN YOUTUBE_PERSONAL_AGP9_KOTLIN_BRIDGE_18_10_6 // Flutter 3.44 + AGP 9 peut fonctionner temporairement avec // android.builtInKotlin=false. Certains plugins regardent uniquement la // version d'AGP et n'appliquent alors plus KGP : leurs sources .kt ne sont // jamais compilees et GeneratedPluginRegistrant ne trouve plus les classes. val youtubePersonalLegacyKotlinPlugins = setOf( "package_info_plus", "wakelock_plus", ) subprojects { if (name in youtubePersonalLegacyKotlinPlugins) { val pluginProject = this pluginManager.withPlugin("com.android.library") { if (!pluginProject.pluginManager.hasPlugin("org.jetbrains.kotlin.android")) { pluginProject.pluginManager.apply("org.jetbrains.kotlin.android") } } } } // END YOUTUBE_PERSONAL_AGP9_KOTLIN_BRIDGE_18_10_6 '@ $gradle = $gradle.TrimEnd() + "`r`n" + $bridge + "`r`n" Set-Content -Path $rootGradle -Value $gradle -Encoding UTF8 Write-Host "[OK] Bridge ajoute dans android/build.gradle.kts" -ForegroundColor Green Write-Host "[4/6] Arret des processus pouvant verrouiller le build..." -ForegroundColor Yellow Get-Process youtube_personal -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue $gradlew = Join-Path $root "android\gradlew.bat" if (Test-Path $gradlew) { Push-Location (Join-Path $root "android") try { & .\gradlew.bat --stop | Out-Host } catch { Write-Host "[INFO] Aucun daemon Gradle a arreter." -ForegroundColor DarkGray } Pop-Location } Write-Host "[5/6] Nettoyage Flutter et resolution des dependances..." -ForegroundColor Yellow $registrant = Join-Path $root "android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java" if (Test-Path $registrant) { Remove-Item $registrant -Force -ErrorAction SilentlyContinue } # On tente un clean complet; si Windows conserve un verrou, on nettoie les # fichiers de metadata essentiels et Flutter regenerera le reste. flutter clean if ($LASTEXITCODE -ne 0) { Write-Host "[ATTENTION] flutter clean incomplet; nettoyage manuel des metadonnees." -ForegroundColor Yellow } foreach ($path in @( (Join-Path $root ".dart_tool"), (Join-Path $root ".flutter-plugins-dependencies") )) { if (Test-Path $path) { Remove-Item $path -Recurse -Force -ErrorAction SilentlyContinue } } flutter pub get if ($LASTEXITCODE -ne 0) { throw "flutter pub get a echoue. Les sauvegardes .before_memory_18_10_6 permettent de revenir en arriere." } Write-Host "[6/6] Build Android Debug de verification..." -ForegroundColor Yellow flutter build apk --debug if ($LASTEXITCODE -ne 0) { Write-Host "" Write-Host "Le bridge a ete applique, mais le build a encore echoue." -ForegroundColor Red Write-Host "Copie uniquement la nouvelle erreur a partir de 'FAILURE: Build failed'." -ForegroundColor Yellow exit 1 } Write-Host "" Write-Host "[OK] Build Android Debug reussi avec le bridge Kotlin AGP 9." -ForegroundColor Green Write-Host "" Write-Host "Tu peux maintenant lancer :" -ForegroundColor Cyan Write-Host " flutter run -d f10778d8" Write-Host "" Write-Host "Puis creer l'APK Release :" -ForegroundColor Cyan Write-Host " flutter build apk --release" Write-Host ""