@echo off setlocal EnableExtensions DisableDelayedExpansion cd /d "%~dp0" echo. powershell -NoProfile -ExecutionPolicy Bypass -Command ^ "$content = [IO.File]::ReadAllText('pubspec.yaml'); " ^ "$match = [regex]::Match($content, '(?m)(?:\A|\r?\n)version:[ \t]*([^\r\n]*)'); " ^ "if (-not $match.Success) { Write-Error 'Could not find the version line in pubspec.yaml.'; exit 1 }; " ^ "Write-Output ('Current version: ' + $match.Groups[1].Value.Trim())" if errorlevel 1 ( echo Could not read the current version. Release cancelled. exit /b 1 ) set "APP_VERSION=" set /p "APP_VERSION=Enter release version (for example 1.0.10 or 1.0.10+2): " if not defined APP_VERSION ( echo No version entered. Release cancelled. exit /b 1 ) powershell -NoProfile -ExecutionPolicy Bypass -Command ^ "$version = $env:APP_VERSION; " ^ "if ($version -notmatch '\A[0-9]+\.[0-9]+\.[0-9]+(\+[0-9]+)?\z') { " ^ " Write-Error 'Use a version like 1.0.10 or 1.0.10+2.'; exit 1 " ^ "}; " ^ "$path = 'pubspec.yaml'; " ^ "$content = [IO.File]::ReadAllText($path); " ^ "$updated = ([regex]::new('(?m)(\A|\r?\n)version:[^\r\n]*')).Replace($content, ('${1}version: ' + $version), 1); " ^ "if ($updated -eq $content) { Write-Error 'Could not find the version line in pubspec.yaml.'; exit 1 }; " ^ "[IO.File]::WriteAllText($path, $updated)" if errorlevel 1 ( echo Version update failed. Release cancelled. exit /b 1 ) echo Updated pubspec.yaml to version %APP_VERSION%. echo Building release APK... flutter build apk --release if errorlevel 1 ( echo Release APK build failed. exit /b 1 ) echo Release APK created at build\app\outputs\flutter-apk\app-release.apk endlocal