Recognize what Gradle is under Android Studio

Source: Internet
Author: User
Tags groovy script

Recognize what Gradle is under Android Studio

What is Gradle? I haven't figured it out at the beginning. The official explanation is:
Gradle is a project automation construction tool based on the concepts of Apache Ant and Apache Maven.
So what is Apache Ant and Apache Maven? Ignore this first. What about automated construction tools?
My personal narrow sense is the software environment deployment and packaging tools. net also has CruiseControl. net continues to integrate WIX to generate the installation package. This is similar, but Gradle is google's parent. Microsoft is not very powerful in this regard. Third-party tools are powerful. However, Microsoft has a good dependency management tool, that isNuGetThis is comparable to Gradle's dependency management.

On zhihu, I found an article with a particularly good explanation and posted it here to prevent the original link from being invalid in the future.

Gradle is a project automation construction tool based on the concepts of Apache Ant and Apache Maven. It uses a Groovy-based domain-specific language to declare Project Settings, rather than traditional XML. Currently, the Supported languages are limited to Java, Groovy, and Scala, and more languages are planned to be supported in the future. The above is the explanation of Gradle on the Wiki. I believe that a person who has never been familiar with building can hardly understand it. So did I. the following is my general understanding of Gradle: software development focuses on code reuse, and reuse can make the project easier to maintain, with less code ..... Developers can reuse code to varying degrees through inheritance, combination, and function modules. however, I wonder if you have ever thought that software development is also a kind of engineering job. It involves not only code writing, but also various project management (dependency, packaging, deployment, and release, management of differences between various channels .....), Every day you build, clean, sign, package, publish, have you ever thought about this process? It can be described like code or reused. for example, I developed Android. You know that there are n Android markets, n mobile phone brands, and n mobile phone sizes in China ......, Generally, companies send packages separately for different markets to measure downloads from different channels. They may need to perform some special processing on mobile phones with different brands, sizes, and other hardware information, in this case, you can create a project separately for different situations, or better you can control it through some variables, such as: if (isMoto) {do something}
Else if (isHuawei) {do something}
...
Difference management, but both of these solutions have their own shortcomings, especially the previous one has a lot of code repetition. the latter is a little better, but the difference in this method is that it is not static at runtime, and the processing logic on the moto mobile phone does not have any effect on the Huawei mobile phone, however, the processing logic for the moto mobile phone is also installed on the Huawei mobile phone, you can use gradle's productFlavor and buildtype to control the differences at the static level. For details, refer to how to use Gradle to implement a set of APK with different features for code development. ByGhui mentioned above multi-channel problems, different Channels generally correspond to different channel numbers. Of course, you can manually create a package at a time to generate your multi-channel package, however, it is reported that a group buying website in China has more than 100 Android apps. what appears here? Repeated, repeated packaging, and the difference between these packages is very small (only the channel number is different). We should reuse them like writing code. Using Gradle, we can execute a command to output all channel packages, A command is used to output the specified channel package. to be more complex, you may need different channels to correspond to different signature files, different icons, and different server addresses... You can use Gradle to conveniently implement these functions. dependency management: for software development, you may need to rely on different jar and library. of course, you can. download the jar/library Project to your local computer and copy it to your project. But I wonder if you have heard of something called a central warehouse abroad, in this repository, you can find all the jar, aar, and... The Central Repository Search Engine can find all The dependencies you need here, and all you need is to specify a coordinate, as shown below: Search for and download The remaining dependencies, you don't need to worry about adding to classpath. The advantages of maintaining dependencies in this way are as follows: search, download, add to classpath, and you don't need to care about the remaining dependencies, the advantages of maintaining dependencies in this way are as follows: dependencies are not stored in your version control repository (cached to ~ by default ~ /. Gradle/) to facilitate version management. For example, 2.3.3 is the version number of picasso, if it is changed to +, it means that the same dependency of different projects of the latest version downloaded from the central repository will not have duplicate copies (only in ~ /War,. war ...) Upload to the specified repository, automatically deploy... Luo Liluo said so much and I wonder if you have understood it. To sum up, Gradle is a building tool that helps you manage differences, dependencies, compilation, packaging, and deployment in projects ......, You can define the build logic that meets your needs and write it to build. gradle for future reuse. gradle is not a programming language. It cannot help you implement any practical functions in the software. It is definitely not a rigorous explanation. You are welcome to discuss anything inappropriate. ### I agree with the slides I shared earlier ### as of now (1432311622353), I have received 342 comments and thanks again for your support! If you think my sharing is helpful to you, please follow me! In the future, I will share more and better content with you. A good slide is here (this is a slide that was previously shared internally at letv and the content has been cut down (for specific projects of the company). This slide references a lot of other materials, the internal link is worth reading)

AS is actually a special version of Intellij IDEA Android Development Environment (Google customized version), Intellij IDEA is a paid version of the IDE. Ant and Maven are both XML-based build tools. Gradle is a build tool written in Groovy, and Groovy is a dynamic and strong type language derived from JVM that is highly compatible with JAVA syntax. Gradle...

AS is actually a special version of Intellij IDEA Android Development Environment (Google customized version), Intellij IDEA is a paid version of the IDE. Ant and Maven are both XML-based build tools. Gradle is a build tool written in Groovy, and Groovy is a dynamic and strong type language derived from JVM that is highly compatible with JAVA syntax. Gradle writes a file named build. the gradle script file sets the project, and then builds the project based on this script (complicated projects also have other files). The Gradle script is essentially a Groovy script, however, the groovy syntax sugar is highly utilized, such as omitting method parameter brackets and ellipsis (;) semicolons to make the Code look like DSL. So almost all the syntaxes supported by java and groovy are supported by its scripts. (It should be okay to use JAVA and GROOVY sdks.) Gradle supports convention-based build and has a wide range of plug-in libraries suitable for different scenarios, more than 20 official user manuals are supported for easy construction. Gradle has two basic concepts: Project and task ). A project consists of multiple tasks. A project can be understood as a build version provided to different devices, such as the desktop, web, Android, and iOS versions, it can also be understood as an action, such as deploying an application to a production environment. A task is equivalent to an Ant target and can be understood as a sub-task in building, such as compilation, packaging, and execution. Note that the commands in Ant, such as javac and copy, are also called tasks, but Ant tasks are far less free than Gradle tasks. Gradle is built in two phases. The first phase is configuration phase, which analyzes build scripts, processes dependencies, and execution sequence. The script itself also needs to be depended on to complete its own analysis. The second stage is the execution phase (execution phase), which truly builds a project and executes various tasks under the project. Ant and Maven are easy to compile for Gradle, but have limited functions and require manual operations. The latter relies on a large dependency warehouse and therefore has powerful external dependency management, however, it is not convenient to add local dependencies, and the project cannot be modified flexibly. Gradle can combine the advantages of Ant and Maven, compile tasks and combine them into projects at will, directly use Maven repository, and support passing dependencies and internal dependencies. (This part is divided into personal subjective opinions, which may not be the same as the opinions of most people) (in fact, it is also the subjective opinions of others, derived from my original Gradle-related articles) in general, Ant buys food, wash food, boil water, cook food, Maven orders food at a restaurant, and Gradle is a 3D printed food.

You have all said that you need to understand it in plain words, so you don't need to learn any theory. In general, gradle is used for packaging. Do you think you have solved your problem? If the problem persists, your problem is not well raised. For example, I guess you should mention: Why do you want to package and release? There are several common methods for packaging and publishing. Why do you need to select gr among these common methods...

You have all said that you need to understand it in plain words, so you don't need to learn any theory. In general, gradle is used for packaging. Do you think you have solved your problem? If the problem persists, your problem is not well raised. For example, I guess you should mention: There are several common methods for packaging, publishing, and gradle among these common methods. For the content I guess, the general saying is: In eclipse, writing a java program is used as an example. Why do we need to package it? After writing it, right-click it and run it. But after the program is written, it is to be published to the server or used by others. First, you cannot install eclipse for all the people to run, and second, you cannot publish the source code to everyone. Therefore, you need to publish your code in binary format to make other environments easy to run. This is packaging. Why do you need to do a lot of things when packaging with ant? For example, the user name and password in the configuration file, the content of your local development and the actual running of the program must be inconsistent, so you need to have two files, use one for development and one for actual running. In this way, you must repeat these tasks during each packaging process. ant allows you to write these tasks as scripts in xml format and then run them automatically. Why use maven to use many jar packages for your project? For example, use log4j to write logs, and use connector to connect to a database. This year, I am embarrassed to go out without using a spring program. The downloaded spring package is opened and I don't know which one to use. Moreover, even if you put these jar packages in, it is very likely that you still cannot run them, because it depends on other jar packages. On which day I want to upgrade a small version of spring, all the jar packages will be re-launched, and you do not remember which jar packages are imported by spring. So with maven, you only need to configure it to use spring 3. All the jar packages have been downloaded for you, and you just need to run it directly. I want to upgrade the version, and change 3 to 4. The new jar package has been downloaded for you. Then? It is convenient to use maven and jar packages, but I still have a lot to do during packaging. Then you will find that maven really does not know how to do these things, so I began to miss ant. Gradle is capable of maven, ant, and writing scripts in the groove language. It is more expressive. This means. === I have watched gradle for the past two days. Simplified Version: ant can automatically package logic. Maven can also be automatically packaged. Compared with ant, it does more to help you download the jar package. However, the packaging logic of maven is too rigid and difficult to customize. It is not as easy as ant. Gradle can automatically download the jar package and write the script by itself, which is easier to write than ant.

Gradle is an engineering build tool. java code and resource files must be processed by some programs in the sdk, such as aapt, to form an apk package. Gradle is to simplify those steps. Equivalent to ant in eclipse!

Gradle is an engineering build tool. java code and resource files must be processed by some programs in the sdk, such as aapt, to form an apk package. Gradle is to simplify those steps. Equivalent to ant in eclipse!

In a word: dependency management and task execution. Like bundler + rake in Ruby, cocoapods in iOS, like npm + grunt in node. in general, it is: which third-party libraries are required for your project, which helps you download them and compile them to the specified location, so you can directly import them and use them. It is based on Apache's...

In a word: dependency management and task execution. Like bundler + rake in Ruby, cocoapods in iOS, like npm + grunt in node. in general, it is: which third-party libraries are required for your project, which helps you download them and compile them to the specified location, so you can directly import them and use them. It is based on Apache ant and maven, but it is not particularly useful. To introduce a library, you have to write a lot of lines of XML, Which is annoying. In addition, they are relatively weak in task execution, so gradle gradually grows and is promoted by Google.

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.