During Google I/O 2016's What's new in Android development tools a great new feature was quickly mentioned: Android Gradle plugin can now automatically download missing dependencies from Android SDK.
It's also mentioned in Android Gradle plugin 2.2.0-alpha4 release notes.
How do I enable it?
In gradle.properties file in your project's root folder add the following line:
android.builder.sdkDownload=true
Note: at the time of writing this option is experimental. It looks like so far it downloads missing build tools and platforms, but doesn't attempt to update repositories where the support libraries or Google Play Services libraries live according to a bug report/feature request.
Edit: since now support libraries and other libraries from Google live on maven.google.com and not in local repositories, the note above isn't as important.
I did:
gradle --refresh-dependencies
on the terminal, and it solved the problem.
Related
After installing arctic fox on linux, I tried to create a new project but was told there was no gradle and it wanted to download one. Not having a great internet connection I downloaded gradle 6.9.2 and I pointed the gradle to the folder.
It's apparently not enough to just have gradle but it needs a plugin as well. Which gets specified in project structure - project. None of the options in project structure work but manually setting version 3.5.3 in the build.gradle does.
The issue I have now is that I have no idea where the 3.5.3 comes from? Is there a folder where all these plugins are installed where one can check what is available?
I'm having the same issue with other dependencies where just starting a new project requires that I re-download all the dependencies again despite the fact that I can open another project and it builds just fine.
The plugin version depend on gradle plugin. You can see version require docs from here: https://developer.android.google.cn/studio/releases/gradle-plugin
And plugin will be downloaded from google maven repository: https://maven.google.com/web/index.html#com.android.tools.build:gradle
You can also find them on your local maven cache directory.
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).
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.
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.