21

I have used clean project a few times after breaking my tutorial app. I did this by doing a refactor or some other fancy command on a variable. I don't actually know what android studio is doing in the background and I am wondering if anyone can give a good detailed answer in simple English. :)

Thank you in advance,

Tyrant911
  • 321
  • 1
  • 2
  • 7
  • Possible duplicate of [Difference between clean project and rebuild project in android studio](https://stackoverflow.com/questions/24083706/difference-between-clean-project-and-rebuild-project-in-android-studio) – TT-- Jan 29 '19 at 22:29

5 Answers5

30

Simple answer it Deletes the build directory

It removes whatever already-compiled files are in your project meaning it removes the .class files and recompiles the project again.

Source is here : https://www.jetbrains.com/help/idea/2016.3/cleaning-system-cache.html?search=clean

If you want to have some fun by cleaning yourself

Open your project path using cmd (go to project path and type cmd and hit enter like below)

enter image description here

Then use command gradlew clean and hit enter and see what happens when it cleans

enter image description here

For other tasks and meet your project's Mr.Gradle use command gradlew help

enter image description here

Charuක
  • 12,953
  • 5
  • 50
  • 88
5

Clean action, basically invoking ./gradle clean task in your application directory, which is removing all generated files, removes build folders. So basically next time you will run/build all the artifacts will be builded from the scratch and will not be reused.

More information you can find on a official gradle site

Information about android plugin

DSL reference for Android plugin

Lebedevsd
  • 950
  • 5
  • 12
1

Cleaning the project removes all build artifacts (ex: deleting the app/build folder)

1

I don't know what it does. But I would like to share my experience that is worth to know.

I was having one Android Studio project in which I was managing two projects through buildTypes(Lets name them project A and B).

I was previously working with project A. Now I need to work on project B. So I made necessary changes and implemented the functionality. My next task was to generate the signed APK. I generated the signed APK with the keystore of appropriate project that is project B.

But the generated signed APK was showing the SHA1 of the keystore of project A. and Google play store was not allowing me to upload the apk with different keystore. I checked it 5 to 6 times and generated signed APK and failed every time.

After 3 to 4 hours I gave one try to clean project as any other solution was not working for me and Voila now it signed the apk with correct keystore.

So clean and rebuild the project before generating the signed APK is a best practice mainly If you are working with different buildTypes

Bhargav Thanki
  • 4,924
  • 2
  • 37
  • 43
1

Cleaning an Android project simply deletes the build directory. It removes the .class files that are generated when you compile your project and then recompiles again. As per my experience, whenever I move my Android Studio project folder in another location in same or different hard drive, it gives an error while running the project. In that case, cleaning the project helps eliminating the errors by re-building the project from scratch and to run successfully. To clear a project in Studio, go to Build > Clean Project. Done.

Sandip
  • 13
  • 4