47.关于gradle的解疑
2015-08-03 17:00
260 查看
Short Answer
Gradle is a build system.Long Answer
Before Android Studio you were usingEclipsefor your development purposes. and the chance may be that you did not know how to build your android project
apkwithout 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
resfolder is in the same directory as your
srcfolder?
This is where the build system enters the picture. The build system automatically takes all the source files (
.javaor
.xml), then applies the appropriate tool (e.g, takes
javaclass files and converts to
dexformat), 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
\srcfolder) or resources files (in Eclipse it is
\resfolder).
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
jarin 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 forgradle.
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.相关文章推荐
- 总结CSS3新特性(Animation篇)
- hdu 3917 Road constructions 最大权闭合子图
- php构造函数连接数据库
- LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- Java学习笔记------如何为文本输入框设置下凹效果?
- 查看linux版本的命令
- hdu 2102 A计划 BFS
- 解决Nginx: [error] open() "/usr/local/Nginx/logs/Nginx.pid
- SpringMVC学习笔记
- Android之MVC模式
- 使用Xcode7非美刀购买开发者帐号,非越狱安装IOS ipa
- js调用oc方法 UIWebView 跳 到另一个UIWebView
- Asp.net 5学习
- node.js学习笔记
- Maven - error in opening zip file
- PHP-FPM之Chroot执行环境详解
- spring mvc 环境搭建
- 传说中的网络流24题
- Hibernate、Mybait,Mysql、Postgresql适用场景
- ConcurrentHashMap缓存