Files
youtube_personal/APPLIQUER_HD_ANDROID.ps1

115 lines
2.9 KiB
PowerShell

param(
[string]$ProjectRoot = $PSScriptRoot
)
$ErrorActionPreference = "Stop"
$androidRoot = Join-Path $ProjectRoot "android"
$rootGradle = Join-Path $androidRoot "build.gradle.kts"
$appGradle = Join-Path $androidRoot "app\build.gradle.kts"
if (-not (Test-Path $rootGradle)) {
throw "Introuvable: $rootGradle"
}
if (-not (Test-Path $appGradle)) {
throw "Introuvable: $appGradle"
}
function Backup-Once([string]$Path) {
$backup = "$Path.before_hd"
if (-not (Test-Path $backup)) {
Copy-Item $Path $backup
Write-Host "Backup: $backup"
}
}
Backup-Once $rootGradle
Backup-Once $appGradle
$rootText = Get-Content $rootGradle -Raw
if ($rootText -notmatch 'https://jitpack\.io') {
$needle = 'mavenCentral()'
if (-not $rootText.Contains($needle)) {
throw "Impossible de trouver mavenCentral() dans android/build.gradle.kts"
}
$replacement = @'
mavenCentral()
maven { url = uri("https://jitpack.io") }
'@
$rootText = $rootText.Replace(
$needle,
$replacement
)
Set-Content -Path $rootGradle -Value $rootText -Encoding UTF8
Write-Host "JitPack ajoute."
} else {
Write-Host "JitPack deja present."
}
$appText = Get-Content $appGradle -Raw
# Nettoie les blocs kotlin/compilerOptions qui ont pu être ajoutés par
# les premières versions du script HD. Ils ne sont pas nécessaires ici:
# AGP 9 fait hériter le jvmTarget de compileOptions.targetCompatibility.
$kotlinCompilerBlock = '(?ms)[ \t]*kotlin\s*\{\s*compilerOptions\s*\{\s*jvmTarget\s*=\s*org\.jetbrains\.kotlin\.gradle\.dsl\.JvmTarget\.JVM_17\s*\}\s*\}\s*'
$appText = [regex]::Replace(
$appText,
$kotlinCompilerBlock,
''
)
if (
$appText -notmatch 'isCoreLibraryDesugaringEnabled\s*=\s*true'
) {
$targetNeedle =
'targetCompatibility = JavaVersion.VERSION_17'
if (-not $appText.Contains($targetNeedle)) {
throw "Impossible de trouver targetCompatibility Java 17 dans android/app/build.gradle.kts"
}
$targetReplacement = @'
targetCompatibility = JavaVersion.VERSION_17
isCoreLibraryDesugaringEnabled = true
'@
$appText = $appText.Replace(
$targetNeedle,
$targetReplacement
)
Write-Host "Core library desugaring active."
}
if ($appText -notmatch '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")
}
'@
$appText = $appText.TrimEnd() + "`r`n" + $dependencyBlock + "`r`n"
Write-Host "Dependances HD ajoutees."
} else {
Write-Host "Dependances HD deja presentes."
}
Set-Content -Path $appGradle -Value $appText -Encoding UTF8
Write-Host ""
Write-Host "Configuration HD Android appliquee."
Write-Host "Lance ensuite:"
Write-Host " flutter clean"
Write-Host " flutter pub get"
Write-Host " flutter run -d f10778d8"