I have updated my gradle-wrapper.properties to 2.10 from 2.8. But I want to know that what its purpose in Android Studio. As we didn't see any gradle-wrapper properties in eclipse.
Gradle Wrapper is a type batch or shell script that downloads and automatically configures Gradle to execute tasks. Imagine that you want to run a Gradle build, well you need to download and install Gradle in your computer, so this concept allows is to distribute our project and build configurations with no need to have Gradle installed.
Also their official gradle webiste says :
Most tools require installation on your computer before you can use
them. If the installation is easy, you may think that’s fine. But it
can be an unnecessary burden on the users of the build. Equally
importantly, will the user install the right version of the tool for
the build? What if they’re building an old version of the software?
The Gradle Wrapper solves both these problems and is the preferred way
of starting a Gradle build.
Related
Gradle is just a build system, right? Why does intellij want to download gradle 2.3 when I have the latest gradle version locally installed. If i setup intellij to use the local distribution, the build fails with an error saying no cached version of gradle 4.3 is available for offline mode.
Point #1, You can point Intellij to a gradle installation. See Intellij Gradle docs that describes your options, but pay special attention to the next point, which intellij also supports.
Point #2 Build systems also have versions. Gradle is constantly being updated, so building with the wrong version of Gradle can fail.
That is why a gradle script can specify the version that it needs in order to build. This is essentially a bootstrapping process designed to make your build scripts essentially self sufficient. See for example Gradle docs that describe this practice.
I'm currently searching for a way to have the Android Gradle automatically install the Android SDK as an dependency, so that the build can complete unattended in our GitLab pipeline.
I already come across the gradle plugin "sdk-manager-plugin", but it is marked deprecated with a note to use the automatic download from gradle. But it does not seam to work. If I run "./gradlew" from within a newly spawned docker container with just java and git it does not work. Is there any way to have gradle download the correct SDK Version (specified with compileSdkVersion)?
And also accept the license terms?
I already tried adding "android.builder.sdkDownload=true" to the "gradle.properties" file, but it didn't seam to work (suggested here How to enable automatic download of missing Android SDK packages in Gradle).
I have a couple of Android project samples I am going to build via the commandline using ./gradlew build on Linux. Whenever I enter this command a message says "Downloading https://services.gradle.org/distributions/gradle-3.3-all.zip". I think I already have the latest gradle under my Android Studio installation path. Why does this have to download gradle every time? Can I specify gradle as an environment variable e.g. GRADLE_HOME so that all projects can use it?
What you have in your Android Studio installation path is not significant when using the Gradle Wrapper (gradlew). It downloads the exact version of Gradle that the current build is designed for and tested with if no other build downloaded it already. The downloaded distributions are stored under ~/.gradle/wrapper/dists/. So as long as you don't delete that folder and you have multiple builds that use the same gradle distribution in the wrapper configuration, that distribution will only be downloaded by the first build you execute. The others will use the already present distribution.
Most resources online say that you update gradle by simply updating the distribution URL. This is the answer all over Stack Overflow and all over.
Codepath also just says that a url update is enough: https://guides.codepath.com/android/Getting-Started-with-Gradle#upgrading-gradle
I've seen scattered throughout a couple of answers that to upgrade gradle you need to run a gradle update script from the command line ./gradlew wrapper --gradle-version x.x.x.
I haven't been able to find documentation that says "This is how you update gradle". On gradles website you can see, "This is how you add the gradle wrapper". I guess I'm not sure what is enough, and I feel like a lot of people are doing it the wrong way, and maybe are not benefiting from performance and speed increases in gradle.
Any canonical answer on this? Someone from the tools team want to comment?
If your project is using the Gradle wrapper then Android Studio will automatically use it. The correct way to upgrade Gradle (via the wrapper) is to run
$ ./gradlew wrapper --gradle-version x.x.x --distribution-type all
The --distribution-type option is supported since Gradle 3.1 and allows to use the all distribution instead of the default bin distribution to get proper IDE support for Gradle build files.
If you are unsure what the latest version x.x.x is, or you are setting up a project from scratch, you might be interested in my gradle_bootstrap.sh helper script which is able to install / update the Gradle wrapper without having Gradle installed. Use it like:
$ gradle_bootstrap.sh all
Just updating the Gradle distribution URL in gradle-wrapper.properties as described in the official docs is not enough in cases where gradle-wrapper.jar itself got updated.
Finally, if you do not use the wrapper yet, Android Studio will prompt to "Click 'OK' to use the Gradle wrapper, or 'Cancel' to manually set the path of a local Gradle distribution", where the latter can point to the Gradle version that ships as part of its installation. At the example of Android Studio 2.2.3 that would be Gradle 2.14.1, which is a bit dated.
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?
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.