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.

时间: 2024-08-27 11:37:42

47.关于gradle的解疑的相关文章

Gradle混淆+打包Jar包基础

本文为原创文章,转载请注明出处. 文章最后会附带源码下载地址,有需要的朋友可下载. 通常我们编写Android APP时有这样的需求:(1)代码混淆:(2)模块化:(3)向第三方提供JAR包.下面将以实例的形式向初学Android或开始使用AndroidStudio(AS)的朋友介绍下这几部分. 引述: (1)AS采用了Gradle的构建工具,可以让我们很方便的对我们的APP进行配置,比如版本.支持最低API level .代码混淆文件.第三方库等等,具体语法请查考其他朋友的文章. (2)AS提

在Gradle中使用jaxb的xjc插件

jaxb,全称为Java Architecture for Xml Binding,是一种将java对象与xml建立起映射的技术.其主要提供两个功能,一是将java对象映射为xml,二是将xml映射为java对象.JAXB有1.0版和2.0版.2.0版对应的JSR(Java specification request, java规格要求)是JSR 222.jaxb中的xjc工具能够将XML Schema转换为对应的java类.支持的XML类型包括XML DTD,XSD以及WSDL.而schema

Android studio启动后卡在refreshing gradle project(包解决)

这个问题几乎每个刚使用Android studio的同学都会碰到过,网上有各式各样的方法,有的说使用本地gradle,我试过多次,每次启动android studio时还是会检查更新,所以根本上解决的办法就是阻止它更新. 其实道理很简单,找到工程里面自动更新请求的地址,把这个地址替换下就好了,不过这个简单的事儿还需要很多动作才能完成. 第一步,要自己下载gradle,地址:点击下载gradle,下载后不必解压: 第二步,在Android studio中找到要修改的工程,工程名->gradle->

gradle 的问题

用命令build app时出现这个错误. Exception in thread "main" java.lang.RuntimeException: Timeout of 120000 reached waiting for exclusive access to file: /Users/weidingqiang/.gradle/wrapper/dists/gradle-2.4-all/3i2gobhdl0fm2tosnn15g540i0/gradle-2.4-all.zip at

[转]-用Gradle 构建你的android程序

出处:http://www.cnblogs.com/youxilua  前言 android gradle 的插件终于把混淆代码的task集成进去了,加上最近,android studio 用的是gradle 来构建项目, 下定决心把android gralde 构建项目的用户指南全部看完, 让不会用gradle 的人也用gradle构建android项目,让打包(注意,打包和构建是两码事)多版本android不再痛苦.最后,题外话:珍惜生命,远离ant.... Gradle build and

Gradle Distributions

Gradle Distributions services.gradle.org/ distributions/ gradle-3.4-rc-3-all.zip 13-Feb-2017 14:55 +0000 87.43M gradle-3.4-rc-3-bin.zip 13-Feb-2017 14:55 +0000 67.05M gradle-3.4-rc-3-src.zip 13-Feb-2017 14:55 +0000 20.37M gradle-3.4-rc-2-all.zip 06-F

Android Studio 第一次新建Android Gradle项目超级慢的解决方案

注: Android Studio 在第一次新建一个 Gradle 项目时需要下载 Gradle ,所以启动很慢( Gradle-bin 大约三十几兆),所以我们应该事先帮他下载好. 首先,我们下载好的 gradle - 版本号 -bin(|all).zip 应该放在哪儿呢. Gradle 有一个 user home ,默认是 C:\Users\[你当前的 用户名] \.gradle . 这个目录下面有四个子文件夹,我们要放到 wrapper\dists \[gradle- 版本号 -bin|a

Gradle入门系列(转)

Gradle是一种构建工具,它抛弃了基于XML的构建脚本,取而代之的是采用一种基于Groovy的内部领域特定语言.近期,Gradle获得了极大的关注,这也是我决定去研究Gradle的原因. 这篇文章是Gradle教程的第一篇,我们有两个目标: 1. 帮助我们学会安装Gradle. 2. 介绍一些基本概念,这有助于我们进一步理解本教程的后面章节. 我们开始吧,先看一下如何安装Gradle. 安装Gradle 如果我们使用的操作系统是Windows或Linux,我们可以根据以下步骤安装Gradle:

Gradle 多渠道打包的使用和错误分析(转)

刚接触到android的开发,对什么都陌生的,本文是自己在项目中使用的技术要点总结,大咖遇到可直接飘过..... 1.Gradle 打包(不废话了直接来脚本),将下列脚本放到build.gradle文件android{}内: 1 defaultConfig{ 2 //applicationId "" //应用包名 3 minSdkVersion 9 //sdk最小支持版本 4 targetSdkVersion 17 //sdk目标版本 5 versionCode 1 6 version