80

What is the difference between the following statements when issued from a Android Studio Project's terminal :

Android_Studio_Project_Path: ./gradlew clean

Android_Studio_Project_Path: ./gradlew clean assembleDebug

Android_Studio_Project_Path: ./gradlew clean :assembleDebug

and normal Android Studio --> Build --> Clean.

What would be the difference in the internal process.

Community
  • 1
  • 1
prago
  • 5,225
  • 5
  • 25
  • 27

3 Answers3

166
  1. ./gradlew clean

    Uses your project's gradle wrapper to execute your project's clean task. Usually, this just means the deletion of the build directory.

  2. ./gradlew clean assembleDebug

    Again, uses your project's gradle wrapper to execute the clean and assembleDebug tasks, respectively. So, it will clean first, then execute assembleDebug, after any non-up-to-date dependent tasks.

  3. ./gradlew clean :assembleDebug

    Is essentially the same as #2. The colon represents the task path. Task paths are essential in gradle multi-project's, not so much in this context. It means run the root project's assembleDebug task. Here, the root project is the only project.

  4. Android Studio --> Build --> Clean

    Is essentially the same as ./gradlew clean. See here.

For more info, I suggest taking the time to read through the Android docs, especially this one.

Community
  • 1
  • 1
kevinmm
  • 3,136
  • 4
  • 21
  • 24
  • 1
    Glad I could be of help. Gradle is awesome, especially for managing complex builds such as Android. I'm looking forward to many other features for native builds coming soon... – kevinmm Dec 02 '15 at 21:06
  • What about shortcut: **Shift+CMD+C**? Why doesn't that delete the build directory? – IgorGanapolsky Nov 02 '16 at 13:39
  • Can you provide a link to that shortcut's description? I couldn't find it [here](https://developer.android.com/studio/intro/keyboard-shortcuts.html), unless I missed it. – kevinmm Nov 02 '16 at 19:41
  • Maybe stupid question, but these commands only remove project/build folder, but project/app/build stays untouch. Can anyone advice how to remove build folders in sub-modules too. Thanks in advance – nuamehas Dec 03 '18 at 10:12
  • 1
    @aruy Not a stupid question. `gradlew clean` should run the `clean` task for the _current project_ directory and any _subprojects_. See [here](https://docs.gradle.org/current/userguide/command_line_interface.html#executing_tasks_in_multi_project_builds). 2 questions you must ask. Is project/app a _subproject_ of the project's build that you are running? Is the project/app/build folder really a build output directory? – kevinmm Dec 05 '18 at 02:50
  • greate but what exaclty differecen sorry I mean whta is purpose of assmbleDebug/ – Nicollas Feb 15 '19 at 17:58
  • @NicollasMatheus this is the _default_ definition of the `assembleDebug` task - https://developer.android.com/studio/build/building-cmdline#DebugMode – kevinmm Feb 16 '19 at 01:08
  • Fyi, the OP was trying to understand the different invocations of the gradle command line. Not what the tasks accomplish. Please note that these tasks can change over different versions of the Android plugin and/or different projects, etc. So, be careful not to assume too much about what each task specifically does. However, unless the build author is really mean, it should achieve the same end result. – kevinmm Feb 16 '19 at 01:09
19

You can also use

./gradlew clean build (Mac and Linux) -With ./

gradlew clean build (Windows) -Without ./

it removes build folder, as well configure your modules and then build your project.

i use it before release any new app on playstore.

Abhishek Garg
  • 3,092
  • 26
  • 30
13

You should use this one too:

./gradlew :app:dependencies (Mac and Linux) -With ./

gradlew :app:dependencies (Windows) -Without ./

The libs you are using internally using any other versions of google play service.If yes then remove or update those libs.

Cristofer
  • 1,046
  • 13
  • 21