81

What is the difference between Clean Project and Rebuild Project (in Android Studio)?

  • I had a problem with the R file about res ids, so I changed the file extension from gif to png and then [my build failed.]
  • I found the solution was to Rebuild Project. This prompts my question above.
TT--
  • 2,956
  • 1
  • 27
  • 46
Fukkong
  • 863
  • 2
  • 7
  • 7

2 Answers2

87

A clean just removes all build artifacts. A rebuild does a clean followed by a build of your project.

EDIT #2 This is 100% true. Refer to this for a thorough demonstration of its correctness.

DSlomer64
  • 4,234
  • 4
  • 53
  • 88
Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
  • 26
    I think that is not true. In both cases I see the following entries in the log. Looks to me like they are identical. 22:54:38 Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources] – vogella Sep 10 '15 at 20:55
  • 8
    Can't see a difference between them either. +1 to @vogella for catching it before me. – SMBiggs Oct 16 '15 at 20:08
  • 2
    This must be a recent change to the gradle rules for Android projects then. Previously it did what I described. – Larry Schiefer Oct 16 '15 at 20:28
  • 3
    Just verified that this is a recent change to Android Studio and the gradle setup. The "Rebuild" doesn't actually create the APK, you have to try to run or export as release first. And, the "Clean" in Android Studio is doing the same tasks as "Rebuild": Clean: `Information:Gradle tasks [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]` Rebuild: `Information:Gradle tasks [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]` – Larry Schiefer Oct 20 '15 at 15:12
  • 42
    Now triply verified. Two menu choices that do exactly the same thing! Thank you Google for keeping Android complicated (job security)! – SMBiggs Nov 16 '15 at 16:24
  • 1
    that's awesome. ha ha..I am using Dagger and when the modules are not detected (due to some issue in code) I was running clean and then rebuild for every fix I was trying. Dagger generates some code so I have to build the project again. So Rebuild should be good. – cgr Dec 21 '16 at 09:52
  • Please note that, as @LarrySchiefer said, `Reuild` does a `Clean` AND THEN COMPILES the code--they ARE DIFFERENT. – DSlomer64 Nov 08 '17 at 12:32
10

What I experienced,

When you do clean, it removes the binaries inside build folders, and postpones building them again to the next run.

When you do rebuild, it does clean and rebuild for those files inside build folder, which rebuilt again in the next run. It does not rebuild the APK!! Which is really weird.

so:

Clean removes the build folders contents.

Rebuild removes the build folder's contents. And builds some binaries; not including the APK!

BTW, I am using Android studio 2.0 Preview 7.

Ajil O.
  • 6,562
  • 5
  • 40
  • 72
MBH
  • 16,271
  • 19
  • 99
  • 149
  • 2
    I just ran clean, it cleaned all modules and then built all. Took several minutes even though expected was to just remove the bin folders which should take like 10sec max. :( – riper Feb 08 '16 at 10:47
  • 1
    @riper There are 2 build(binaries) folders, one inside app module, the other for the whole app, both of them are cleaned and regenerated after clean, so it takes some time special if the gradle working online, it will check all your libraries etc.. – MBH Feb 08 '16 at 11:34