What's gradle in Android studio?

Source: Internet
Author: User

Ghui
Links: https://www.zhihu.com/question/30432152/answer/48239946
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

Gradle is a project automation building tool based on the Apache Ant and Apache maven concepts. It uses a particular domain-specific language based on groovy to declare project settings, rather than traditional XML. Currently its supported languages are limited to Java, groovy, and Scala, and plans will support more languages in the future.

Above is the wiki on the gradle explanation, believe that a person who has not contacted the construction is not able to understand, at the beginning I also. Here is my understanding of Gradle's popularity :

Software development is about code reuse, and reuse can make engineering easier to maintain and less code ..... Developers can achieve varying degrees of code reuse through inheritance, composition, function modules, and so on. But I don't know if you think about it, software development is also a kind of engineering work, not only write code, but also involves various management of engineering (dependency, packaging, deployment, release, differential management of various channels ...), You are Build,clean, signing, packing, publishing, thinking about this process, and can be described as code, can be reused.

As an example,

I do Android development, you can know that there are n Android Market in China, N mobile phone brands, n mobile phone size ..., the general company will be a separate contract for different markets to count the number of downloads of different channels, etc., may need to target different (brand, size and other hardware information) Mobile phone to do some special processing, this time you can build a project for different situations, or a little better you can control it by some variables, like this:

if (Ismoto) {do something}else if (Ishuawei) {do something} ...

Variance Management

But both solutions have their drawbacks, especially the previous one with great code duplication. The latter is slightly better, but the difference in this way is run-time, not static, and the processing logic on the Moto phone has no effect on the Huawei phone, But this process logic for the Moto mobile phone is also installed on the Huawei mobile phone, through the Gradle Productflavor and BuildType can achieve static level of differential control can refer to how to implement a set of code to develop different features apk Byghui

Speaking of the front of the multi-channel problem, different channels will generally correspond to different channel numbers, you can of course, by modifying a package this pure manual way to generate your multi-channel package, but it is heard that the domestic purchase site of the Android app has more than 100 channels. What's happening here? Repeated packaging and these packages before the difference is very small (but the channel number is different), and write code like we should reuse, through the gradle can achieve a command to play all the channel package, a command to play the designated channel package. A little more complicated, you might need different channels for different signature files, Different icon, different server address ... All of these can be conveniently implemented by Gradle.

Dependency Management:

To do software development you may need to rely on a variety of different jar,library. You can of course download the. Jar/library project locally and copy it to your project, but I wonder if you've ever heard of something called a Central warehouse abroad, In this warehouse you can find all the jar,aar you can think of and you have never heard of. The central Repository Search Engine Here you can find all the dependencies you need, and all you need to do is specify a coordinate, as follows:

https://pic4.zhimg.com/8883d4b758b288a74eb4c104db854c5f_b.jpg" Data-rawwidth= "data-rawheight=" "class=" Content_image "width=" > "The rest of the dependent search, download, add to Classpath and so you do not need to care, The benefits of maintaining dependencies in this way are as follows:

The rest depends on the search, download, add to classpath etc you don't need to care, in this way to maintain the benefits of dependency have the following points:

    1. Dependencies will not go into your version control repository (the default will be cached to ~/.gradle/)
    2. Easy to unload load dependency (just a coordinate dependency, no need to delete)
    3. Convenient version management, such as 2.3.3 in the Picasso version number, if you change to + means to download the latest version from the Central warehouse
    4. There is no duplicate copy of the same dependency on different projects (only one copy exists under ~/.gradle)

Project deployment

I haven't had much contact with this, but as far as I know through some plugins, you can automate your output (. Jar,.apk,.war ...) Upload to the specified warehouse, auto-Deploy ...

Preaching said so much, I don't know if you understand

To summarize:

    1. Gradle is a build tool that can help you manage differences, dependencies, builds, packages, and deployments ... in your project, you can define the build logic that meets your needs and write it to the Build.gradle for later reuse.
    2. Gradle is not a programming language , it does not help you implement any actual functionality in the software

The popular explanation is certainly a non-rigorous explanation, the inappropriate place welcomes the discussion.

What's gradle in Android studio?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.