47.关于gradle的解疑
Short Answer
Gradle is a build system.
Long Answer
Before Android Studio you were using Eclipse
for your development purposes. and the chance may be that you did not know how to build your android project apk
without even 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 to dex
format), 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 also learned from their shortcomings. It is 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 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 jar
in case of Java) from sources then you can write a complete plugin in Java or Groovy, and distribute it to rest of world.
Why did google take it?
Google saw one of the most advanced build systems on the market and realised 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 write in script?
Simple example can be that you have to copy some files from one directory to another before the actual build process happens.
47.关于gradle的解疑的更多相关文章
- ionic build android error when download gradle
这里我遇到一个问题,当用 ionic build android 的时候,无数次build,无数次失败的时候,我真想骂一句,NND的GNF,我又想起武大的臭鸡蛋,是的,该丢,发明这种东西的人,难道不 ...
- 在Gradle中使用jaxb的xjc插件
jaxb,全称为Java Architecture for Xml Binding,是一种将java对象与xml建立起映射的技术.其主要提供两个功能,一是将java对象映射为xml,二是将xml映射为 ...
- 使用Gradle构建构建一个Java Web工程及持续集成环境Jenkins配置
安装Eclipse插件——Buildship 什么是Buildship? Buildship能方便我们通过Eclipse IDE创建和导入Gradle工程,同时还能执行Gradle任务. Eclips ...
- Gradle build设置自动log开关
应用场景 通常情况下我们的apps发布后也就是release模式下log是不显示的,debug模式下是显示log的,但是在特殊情况下我们测试release包的时候需要log的时候,就无法使用Build ...
- 深入理解gradle编译-Android基础篇
深入理解gradle编译-Android基础篇 导读 Gradle基于Groovy的特定领域语言(DSL)编写的一种自动化建构工具,Groovy作为一种高级语言由Java代码实现,本文将对Gradle ...
- Android Studio 第一次新建Android Gradle项目超级慢的解决方案
大家有什么问题,欢迎问我! 注:Android Studio在第一次新建一个Gradle项目时需要下载Gradle,所以启动很慢(Gradle-bin大约三十几兆),所以我们应该事先帮他下载好. 首先 ...
- 错误异常 (1)Android Studio错误提示:Gradle project sync failed. Basic functionality (eg. editing, debugging) will not work properly
[已解决]Android Studio错误提示:Gradle project sync failed. Basic functionality (eg. editing, debugging) wil ...
- 使用gradle创建java程序
创建一个Java项目 我们可以使用Java插件来创建一个Java项目,为了做到这点,我们需要把下面这段语句加入到build.gradle文件中: 1 apply plugin: 'java' 就是这样 ...
- [转]-用Gradle 构建你的android程序
出处:http://www.cnblogs.com/youxilua 前言 android gradle 的插件终于把混淆代码的task集成进去了,加上最近,android studio 用的是gr ...
随机推荐
- C# 获取当前文件、文件夹的路径及操作环境变量
一.获取当前文件的路径 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName 获取模块的完整路径,包 ...
- C#访问修改符
修饰符可以指定访问的可见性,还可以指定其本质.(文章摘自<C#高级编程(第9版)>以及Microsoft) 1. 可见性修饰符 public:应用于所有类型或成员,即任何代码均可以访问该项 ...
- http请求各种数据的接受
一.接受请求的http数据 1.接受客户请求的数据,例如xml数据格式,代码如下: 此代码相当于服务端 public String analyzeWeixinXMLStr(HttpServletReq ...
- OpenGL glReadPixels 转成 CImage
本来是一件很简单的事情,就是将View上使用OpenGL画出来的数据生成图片让其实现打印的功能,我们知道MFC提供打印的接口是不支持OpenGL的(至少我不清楚),必须将它转成GDI再画在Print的 ...
- Redis基础对象
Redis 中每个对象都由一个 redisObject 结构表示 typedef struct redisObject { //类型 unsigned type:; //编码 unsigned enc ...
- C语言exp()函数:e的次幂函数(以e为底的x次方值)
头文件:#include <math.h> exp()用来计算以e 为底的x 次方值,即ex 值,然后将结果返回.其原型为: double exp(double x); [返回值]返 ...
- Problem G: 角谷步数
Problem G: 角谷步数 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 78 Solved: 28[Submit][Status][Web Bo ...
- NOIP2018 全国热身赛 第二场 (不开放)
NOIP2018 全国热身赛 第二场 (不开放) 题目链接:http://noi.ac/contest/26/problem/60 一道蛮有趣的题目. 然后比赛傻逼了. 即将做出来的时候去做别的题了. ...
- Iframe父子间元素操作
1.在父页面 获取iframe子页面的元素 (在同域的情况下 且在http://下测试,且最好在iframe onload加载完毕后 dosomething...) js写法 a.通过contentW ...
- Mbps、Kbps、bps、kb、mb区别和换算
Mbps 即 Milionbit pro second(百万位每秒) Kbps 即 Kilobit pro second(千位每秒) bps 即 bit pro second(位每秒) 速度单位,bi ...