Files
youtube_personal/REPARER_HD_ANDROID_KOTLIN_DSL.ps1

94 lines
2.6 KiB
PowerShell

param(
[string]$ProjectRoot = $PSScriptRoot
)
$ErrorActionPreference = "Stop"
$appGradle = Join-Path $ProjectRoot "android\app\build.gradle.kts"
if (-not (Test-Path $appGradle)) {
throw "Introuvable: $appGradle"
}
$backup = "$appGradle.before_hd_kotlin_dsl_fix"
if (-not (Test-Path $backup)) {
Copy-Item $appGradle $backup
Write-Host "Backup: $backup"
}
$text = Get-Content $appGradle -Raw
# Avec l'AGP 9 Kotlin intégré, jvmTarget hérite déjà de
# android.compileOptions.targetCompatibility. Notre bloc kotlin {}
# ajouté pour la HD est donc inutile et, sur cette combinaison
# Flutter/Gradle, n'a pas d'accesseur Kotlin DSL disponible.
#
# On retire uniquement le bloc précis que notre correctif précédent
# avait ajouté, qu'il soit au niveau racine ou dans android {}.
$kotlinCompilerBlock = '(?ms)[ \t]*kotlin\s*\{\s*compilerOptions\s*\{\s*jvmTarget\s*=\s*org\.jetbrains\.kotlin\.gradle\.dsl\.JvmTarget\.JVM_17\s*\}\s*\}\s*'
$count = [regex]::Matches(
$text,
$kotlinCompilerBlock
).Count
if ($count -gt 0) {
$text = [regex]::Replace(
$text,
$kotlinCompilerBlock,
''
)
Write-Host "Bloc kotlin/compilerOptions retire ($count occurrence(s))."
} else {
Write-Host "Aucun bloc kotlin/compilerOptions HD a retirer."
}
# On conserve Java 17 et le desugaring nécessaire à NewPipe.
if (
$text -notmatch 'isCoreLibraryDesugaringEnabled\s*=\s*true'
) {
$needle =
'targetCompatibility = JavaVersion.VERSION_17'
if (-not $text.Contains($needle)) {
throw "targetCompatibility Java 17 introuvable dans $appGradle"
}
$text = $text.Replace(
$needle,
"targetCompatibility = JavaVersion.VERSION_17`r`n isCoreLibraryDesugaringEnabled = true"
)
Write-Host "Core library desugaring active."
}
# Vérifie que les dépendances de l'étape HD existent toujours.
if (
$text -notmatch 'com\.github\.TeamNewPipe:NewPipeExtractor:v0\.26\.3'
) {
$dependencyBlock = @'
dependencies {
implementation("com.github.TeamNewPipe:NewPipeExtractor:v0.26.3")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs_nio:2.1.5")
}
'@
$text = $text.TrimEnd() + "`r`n" + $dependencyBlock + "`r`n"
Write-Host "Dependances HD restaurees."
}
Set-Content -Path $appGradle -Value $text -Encoding UTF8
Write-Host ""
Write-Host "Correctif Kotlin DSL applique."
Write-Host "Le bloc kotlin {} ajoute par l'etape precedente a ete retire."
Write-Host ""
Write-Host "Lance maintenant:"
Write-Host " flutter clean"
Write-Host " flutter pub get"
Write-Host " flutter run -d f10778d8"