What is Gradle in Android Studio?

转载 2016年05月30日 16:10:58

转载自:http://stackoverflow.com/questions/16754643/what-is-gradle-in-android-studio

Short Answer

Gradle is a build system.

Long Answer

Before Android Studio you were using Eclipse for your development purposes, and, chances are, you didn't know how to build your Android APK without Eclipse.

You can do this on the command line, but you have to learn what each tool (dx, aapt) does in the SDK. Eclipse saved us all from these low level but important, fundamental details by giving us their own build system.

Now, have you ever wondered why the res folder is in the same directory as your src folder?

This is where the build system enters the picture. The build system automatically takes all the source files (.java or .xml), then applies the appropriate tool (e.g. takes java class files and converts them to dex files), and groups all of them into one compressed file, our beloved APK.

This build system uses some conventions: an example of one is to specify the directory containing the source files (in Eclipse it is \src folder) or resources files (in Eclipse it is \res folder).

Now, in order to automate all these tasks, there has to be a script; you can write your own build system using shell scripting in linux or batch files syntax in windows. Got it?

Gradle is another build system that takes the best features from other build systems and combines them into one. It is improved based off of their shortcomings. It is a JVM based build system, what that means is that you can write your own script in Java, which Android Studio makes use of.

One cool thing about gradle is that it is a plugin based system. This means if you have your own programming language and you want to automate the task of building some package (output like a JAR for Java) from sources then you can write a complete plugin in Java or Groovy, and distribute it to rest of world.

Why did Google use it?

Google saw one of the most advanced build systems on the market and realized that you could write scripts of your own with little to no learning curve, and without learning Groovy or any other new language. So they wrote the Android plugin for Gradle.

You must have seen build.gradle file(s) in your project. That is where you can write scripts to automate your tasks. The code you saw in these files is Groovy code. If you write System.out.println("Hello Gradle!"); then it will print on your console.

What can you do in a build script?

A simple example is that you have to copy some files from one directory to another before the actual build process happens. A Gradle build script can do this.

[Android Studio系列(五)] Android Studio手动配置Gradle的方法

1 问题(1) android sutdio第一次打开一个工程巨慢怎么办? (2) 手动配置Gradle Home为什么总是无效? (3) 明明已经下载了Gradle,配置了gradle home...
  • fuchaosz
  • fuchaosz
  • 2016年06月02日 15:58
  • 55852

AndroidStudio使用Gradle-高级篇

上一篇AndroidStudio使用Gradle-基础篇还留下了gradle一些比较实用的点没有介绍,这里介绍下其他细节。 相关资料 Gradle Plugin for Android 类参考 h...
  • be_happy_mr_li
  • be_happy_mr_li
  • 2016年09月20日 21:26
  • 605

Android studio使用之[gradle的使用]

Android studio使用之[gradle使用] gradle的相关介绍 gradle相关命令 使用gradle进行多渠道打包 gradle的相关介绍在Android Studio中有一个不可或...
  • qq_29924041
  • qq_29924041
  • 2017年04月22日 15:33
  • 2508

android studio gradle 国内代理

使用阿里云的国内镜像仓库地址,就可以快速的下载需要的文件 修改项目根目录下的文件 build.gradle : buildscript { repositories { ...
  • ke_csdn
  • ke_csdn
  • 2017年03月29日 16:41
  • 3745

Android Studio Gradle环境变量配置

Gradle是Android Studio用来构建和管理项目的一个插件,采用了基于Groovy的内部领域特定语言。Android Studio已经帮我们封装了很多Gradle命令,还可以通过控制台Co...
  • qq402164452
  • qq402164452
  • 2017年04月17日 08:49
  • 3692

Android Studio手动下载配置Gradle的方法

问题(1) Android sutdio第一次打开一个工程巨慢怎么办? (2) 手动配置Gradle Home为什么总是无效? (3) 明明已经下载了Gradle,配置了gradle home...
  • hp910315
  • hp910315
  • 2017年04月13日 16:49
  • 18298

Android Studio更新Gradle方法

Android Studio的Gradle更新经常会遇到,但是大家都懂的,由于被墙的原因每次更新都非常困难,经常卡死,有时停止在Refreshing Gradle Project ,有时新建项目的时...
  • Momentyol
  • Momentyol
  • 2017年02月19日 12:54
  • 5305

android studio 一直卡在Gradle:Build Running的解决办法

在使用AS开发安卓应用程序的时候经常会遇到Gradle build running一直在运行甚至卡死的情况,本文列出了几种解决方法以供参考。...
  • a549742320
  • a549742320
  • 2016年09月13日 13:52
  • 36098

Android Studio 之 Gradle 安装配置和编译

目录目录 前言 Gradle简介 Gradle安装 Gradle构建项目 XYALLappbuildgradle模块gradle配置文件 XYALLbuildgradle整个项目的gradle配置文件...
  • zinss26914
  • zinss26914
  • 2015年09月22日 15:07
  • 14730

【个人笔记】android studio gradle 两种更新方法更新

android studio gradle 两种更新方法更新 第一种.Android studio更新 第一步:在你所在项目文件夹下:你项目根目录gradlewrappergradle-w...
  • u011320770
  • u011320770
  • 2017年10月25日 10:40
  • 252
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:What is Gradle in Android Studio?
举报原因:
原因补充:

(最多只允许输入30个字)