[Transfer]-gradle User Manual (a): Why use Gradle?

Source: Internet
Author: User
Tags maven central

Original address: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Using-sourceCompatibility-1.7

Translation: Android Studio Chinese Group (sledgehammer translation)

Given that Android Studio uses Gradle to build projects, there are a number of headaches that can be encountered during the IDE's use. Sledgehammer is also the first contact, in order to have a basic understanding, special to find the official Android manual, and we learn together. Translation of the wrong place, I hope to point out.

Why do you use Gradle?

Gradle is a more advanced build system and a good build tool that allows custom build logic through plugins

The following are the main reasons why Android Studio chooses Gradle:

    • Use domain-specific languages (domain specific Language) to describe and manipulate building logic. (hereinafter referred to as DSL)
    • Based on groovy. DSLs can mix various declarative elements and manipulate these DSL elements in code to achieve logical customization.
    • Support for existing MAVEN or Ivy warehouse infrastructure
    • Very flexible, allowing the use of best practices, does not force you to follow its principles.
    • Other plugins can expose their own DSL and API to let Gradle build files for use.
    • Allows IDE integration, is a good API tool


Need to prepare:

    1. Gradle 1.6 or 1.7
    2. SDK with Build Tools 17.0.0 (released 5/16/2013)

Basic Project

In the root directory of the Gradle project, there is a file called Build.gradle, which describes the overall building base of the project.

Build File

The most basic Java program, its build.gradle file is a word:

Apply plugin: ' java '

The most basic Android project, it's Build.gradle as follows:

Buildscript {
repositories {
Mavencentral ()
}

dependencies {
Classpath ' com.android.tools.build:gradle:0.5.6 '
}
}

Apply plugin: ' Android '
Android {
Compilesdkversion 17
}

Let's take a step-by-step look at the contents of the above three sections.

    • buildscript{.} Configures the code for the drive build, which declares that it will take a classpath dependency in the Maven central repository, that is, Android plugin for Gradle v0.5.6
    • Apply plugin indicates that the plugin used is Android, as in the previous Java program, plugin is Java
    • Android{...} All Android built parameters are configured here, which is the entry point for the Android DSL.

By default, only the target compilation environment is necessary, that is, the Compilesdkversion property. This is similar to the target property used in Project.Properties.

It is important to note that if you write apply Plugin:java instead of apply plugin:android on an Android project, the build will fail.

[Transfer]-gradle User Manual (a): Why use Gradle?

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.