Skip to content

Instantly share code, notes, and snippets.

@humazed
Last active July 2, 2024 06:12
Show Gist options
  • Select an option

  • Save humazed/0d0c5fc7b0bf7c87adfa2cf5f75b2e30 to your computer and use it in GitHub Desktop.

Select an option

Save humazed/0d0c5fc7b0bf7c87adfa2cf5f75b2e30 to your computer and use it in GitHub Desktop.
powershell script for cleaning up build files in all Flutter and Android projects
Write-Host "Cleaning up build files in all Flutter and Android projects..."
$rootPath = Get-Location
Get-ChildItem -Path $rootPath -Recurse -Directory | ForEach-Object {
$currentDir = $_
$flutterProject = Join-Path $currentDir.FullName "pubspec.yaml"
$androidProject = Join-Path $currentDir.FullName "android\gradlew"
if (Test-Path $flutterProject) {
Write-Host "Cleaning Flutter project in $($currentDir.FullName)..."
Set-Location $currentDir.FullName
& flutter clean
}
if (Test-Path $androidProject) {
Write-Host "Cleaning Android project in $($currentDir.FullName)..."
Set-Location (Join-Path $currentDir.FullName "android")
& .\gradlew clean
Set-Location $rootPath
}
# Delete APK files, AAB files, other build files, and additional useless files
Get-ChildItem -Path $currentDir.FullName -Recurse -Include *.apk, *.aab, *.a, *.log, *.tmp, *.bak, *.swp, .DS_Store | Remove-Item -Force
# Delete unnecessary folders
$foldersToRemove = @("build", "node_modules", "temp")
$foldersToRemove | ForEach-Object {
$folderPath = Join-Path -Path $currentDir.FullName -ChildPath $_
if (Test-Path $folderPath) {
Remove-Item -Recurse -Force $folderPath
}
}
}
Write-Host "All done! Build files and other useless files have been cleaned up in all projects."
@apoorvpandey0
Copy link

For anyone facing issue that the script starts downloading gradle.zip unnecessarily, simply remove the if androidProject part from the script and run. It'll clean all flutter projects!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment