What is Gradle in Android Studio?
来源:互联网 发布:压力传感器 淘宝 编辑:程序博客网 时间:2024/05/24 03:01
转载自: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 Gradle in Android Studio?
- what is Activity in Android
- android studio gradle编译报错:it is currently in use by another gradle instance
- What is Gradle
- Gradle in Android Studio (2) - 配置Gradle
- What is the shortcut to Auto import all in Android Studio?
- 报错:”Gradle error : Write access is allowed from event dispatch thread only in android studio
- 报错:”Gradle error : Write access is allowed from event dispatch thread only in android studio
- 报错:”Gradle error : Write access is allowed from event dispatch thread only in android studio
- Gradle error : Write access is allowed from event dispatch thread only in android studio
- Gradle Sync issue in Android Studio
- Gradle in Android Studio (3) - 项目中的Gradle
- [Android Studio] Gradle fails to resolve dependencies in Android Studio
- what is the purpose of using translatable in Android strings?
- android studio is not translated in
- 解决Android studio导入项目gradle location is incorrect问题
- Android Studio, gradle plugin is too old or set ANDROID_DAILY_OVERRIDE
- Android studio导入项目gradle location is incorrect问题
- HaDoop学习
- Leetcode 290. Word Pattern
- 算法7— 判断一个单链表是否有环,如果有,找出环的起始位置
- 【学习】正则表达式
- [实践] Android5.1.1源码 - 在Framework中添加自定义系统服务
- What is Gradle in Android Studio?
- iOS 探讨之 正则表达式
- vim配置强悍来袭
- 关于数据库where和having的区别、group by 与having如何使用。
- Java4Android第2课:数据类型
- 自定义控件 浅述
- 仿微信长按弹出popwindow效果
- 12、JNI基本资料
- android中TextView的Spnnable使用