32

I am backing up android studio projects in google drive and I found that the build folders contain thousands of files, so google drive ends up tired.

My practice is that I run the 'clean project' command in Android Studio before exiting so that the unnecessary files are cleaned and only the important files remain to be backed up. But still sometimes the build folder remains there with many files.

My question is that if I delete these two build folders manually (see screenshot), will my project rebuild again on next startup, or will it mess up my project?

Two build folders

3
  • 7
    Yes, you can safely delete those. The Android Studio has an Export to zip file option under the File menu that automatically zips the entire project folder excluding build folders and cache (Not sure when this was introduced, I have it in version 3.2)
    – Kathir
    Nov 30, 2018 at 13:30
  • I've rolled back your edit, because answers go in the answer section. If you have an alternative solution, post an answer rather than editing the question.
    – Zoe
    May 19, 2019 at 10:09
  • This edit cannot be an answer because the question is entirely different and my edit does not answer the question in any way. I wrote this because this was related and people interested in the question would find it useful.
    – Usman
    May 20, 2019 at 11:41

6 Answers 6

23

will my project rebuild again on next startup

Yes. For situations where backups are expensive in terms of space, time, or money, follow the rules for what goes into version control (e.g., git), and back up only those things.

17

If you are using a unix based OS you might be able to run following command using terminal:

 find . -name build -exec rm -rf {} \;

which causes to delete all build folders inside a specific folder.

2
  • 2
    This has a potential to delete all build directories, not just the Android-related ones which may be dangerous and unwanted (eg. in mixed TS/Android projects one could be storing JS in build — why clearing Android files should clear JS too). For what it's worth I have been able to delete only android/build directories using: find ./**/android -name 'build' -type d -prune -print -exec rm -rf '{}' \; Jan 1, 2021 at 8:17
  • 1
    @StanisławChmiela Used your command to delete about 50 GB of old build folders I had accumulated for past 8 years of development. Great find. Mar 22, 2022 at 7:11
5

Removing the build file doesn't mess up application but yes it gets created again and it rebuilds the application. If you read the below link they have clearly mentioned why build file is created and required.

https://developer.android.com/studio/build/index.html

Hope this helps.

4

You can do one thing as I do. Just keep app folder and delete remaining folders. When you need to use that project again. Create new project and replace that app folder with your and done.

2

The best practice is to use a version control system like git, it generates a .gitignore file where the unnecessary files are mentioned. (this files are created then by youy IDE) example of gitignore:

.iml

.gradle

/local.properties

/.idea/workspace.xml

 /.idea/libraries

.DS_Store

/ build

/ captures

.externalNativeBuild

*.idea

.idea / modules.xml
0
1

Yes, you can delete the Build folder.

If you are running Windows and you are not able to delete the folder, make sure you are the owner of the folder. Go to folder properties/security and check if your name is listed as the owner.

Also, make sure you mark the "full control". This will surely delete the folder. Next time when you run Android Studio, the necessary build stuff will be created by Android Studio.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.