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.

相关文章推荐

What is new in Android security (M and N Version) - Google I/O 2016 翻译

截至发博,字幕还在后期中,应该快了吧。 YouTube视频链接:https://www.youtube.com/watch?v=XZzLjllizYs字幕翻译: 1 00:00:01,820 –...
  • mpx_xb
  • mpx_xb
  • 2016年10月09日 16:21
  • 778

What is the difference between getWidth/heigth() and getMeasuredWidth/Heigth() in Android SDK?

From: http://stackoverflow.com/questions/8657540/what-is-the-difference-between-getwidth-heigth-and-...
  • fyfcauc
  • fyfcauc
  • 2014年10月11日 16:54
  • 391

This version of Android Studio is incompatible with the Gradle Plugin used.

今天因为该问题导致,我花费了一天的时间。不过也因此学到了东西,不怕问题,没有解决不了的问题。找准问题所在,一定能解决。 我们直接进去正题, 英文:This version of Android ...

AndroidStudio运行项目出现This version of Android Studio is incompatible with the Gradle Plugin used.

问题描述: 我在gitHub上新下载了一个Demo,可是运行时发现有这个错误,在它的 gradle-wrapper.properties 这个文件夹中发现它的gradle版本是3.3的,而我的grad...

Error running app: This version of Android Studio is incompatible with the Gradle Plugin used. Try d

在开发中从代码仓库导入项目时,突然遇到个问题, 就是cline 和 Rebuile 都没有问题 ,但是一运行就报Error running app: This version of Android ...

android studio 一次编译错误:Error:Minimum supported Gradle version is 2.14.1.

因为需要,今天从git上重新下载工程到另一个目录下,结果运行的时候报了这个错:Error:Minimum supported Gradle version is 2.14.1.  Current ve...

This version of android studio is incompatible with the gradle version used.

问题背景 因为项目app分包需要,将工程的graddle版本升至了2.2.0 alpha4,而我的android studio 一向升级为最新版,于是就出现了题目中的报错: Error running...

This version of Android Studio is incompatible with the Gradle Plugin used

问题背景 因为项目app分包需要,将工程的graddle版本升至了2.2.0 alpha4,而我的Android studio 一向升级为最新版,于是就出现了题目中的报错: Error running...

This version of Android Studio is incompatible with the Gradle Plugin used. Try disabling Instant Ru

用AS导入网易云信SDK时,编译出现“This version of Android Studio is incompatible with the Gradle Plugin used. Try d...

关于android studio出现Gradle sync failed: Plugin is too old, please update to a more recent version

今天打开as出现以下错误信息: Gradle sync failed: Plugin is too old, please update to a more recent version,or ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:What is Gradle in Android Studio?
举报原因:
原因补充:

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