In android studio when we build the project there are two options for building the project in:
settings->build Tools->Gradle->Project-level settings
The first option is "Use default gradle wrapper" and the second option is "Use local gradle distribution"
My question is which option is faster and when will it be used?
The default is the current version. Once you have upgraded the wrapper, you can check that it's the version you expect by executing ./gradlew --version . Example: Upgrading the Wrapper version. $ ./gradlew wrapper --gradle-version 7.5.1 BUILD SUCCESSFUL in 4s 1 actionable task: 1 executed.
The Gradle wrapper is a script you add to your Gradle project and use to execute your build. The advantages are: you don't need to have Gradle installed on your machine to build the project. the wrapper guarantees you'll be using the version of Gradle required by the project.
gradle file, located in the root project directory, defines dependencies that apply to all modules in your project. By default, the top-level build file uses the plugins block to define the Gradle dependencies that are common to all modules in the project.
You can read about Gradle Wrapper in the official user guide.
The main thing about the wrapper - it cares about the Gradle version used to build your project. So, if one has configured the project to use a wrapper, then everyone will build it with the same version of Gradle. The version of Gradle could be specified in the configuration file called gradle-wrapper.properties
.
One more important thing is that Gradle distribution will be included in your project and if someone will try to build it, no local Gradle installation will be needed.
But if you choose use local gradle distribution, then your project will be built with the version of Gradle you have currently installed and it doesn't guarantees, that your project will be built correctly, since Gradle version may differ.
I don't think, that time is different for this two cases, but wrapper usage seems to be preferable. Sure, in this case, you have to store wrapper distribution in your version control system, but you can set build tool version exactly used to build your project and make no one install Gradle manually if he doesn't have Gradle installed yet.
I want to add a very important point to the Stanislav's answer. Gradle could be used not only for building your project from Android Studio, but also the from command line. This is especially important if you want to build it in CI environment. In that case, you don't need to care about specific gradle version on your server. The project will be built with the same version for both IDE and CI and this will make your build stable and predictable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With