Last active
July 2, 2024 06:12
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone facing issue that the script starts downloading gradle.zip unnecessarily, simply remove the
if androidProjectpart from the script and run. It'll clean all flutter projects!