当前位置:网站首页>gradle脚本中groovy语法讲解
gradle脚本中groovy语法讲解
2022-08-02 03:27:00 【浮空over】
文章目录
一、build的生命周期(Glide脚本的生命周期)
初始化期:initialization—>配置期:configuration—>执行期:execution
二、gradle命令
执行打包命令,首先找到你所在module的目录,
可以打成APK也可以打成aar,你如果只有一个app就到app下,执行如下命令
(1)gradle clean
(2) gradle assembleDebug
(3)gradle assembleRelease
三、gradle的三种对象
gradle主要有三种对象:
- Gradle对象:构建初始化时创建,整个构建执行过程中只有这么一个对象,一半很少去修改这个默认配置脚本
- Settings对象:每个settings.gradle都会转化成1一个Settings对象
- Project对象:每个build.gralde都会转换成一个Project对象
四、groovy语法
1.字符串拼接
def str1 = "aaa"
def str2 = 'bbb'
println(str1+str2)
println "$(str1)$(str2)
2.List
def list = [1,2,3,4,5]
println list[0]
//遍历
list.each{
//每一个元素可以用it表示
println it
}
for(int i in 1..5){
println list[i]
}
3.map
def map = ['name':'jack','age':19]
println map['name']
map.each{
println "key:${it.key},value:${it.value}"
}
4.定义一个方法
def methodA(int a,int b){
a+b
//gradle默认将最后一行非空行(有代码行)作为结果返回
}
5.定义一个对象
//groovy没有私有这一说
class Student{
String name
int age
String getName() {
return name
}
void setName(String name) {
this.name = name
}
int getAge() {
return age
}
void setAge(int age) {
this.age = age
}
}
6.闭包
//测试闭包
task closure{
mEach {
println it
}
}
//闭包-》钩子或者接口,在gradle只对{}里面有效,Closure
def mEach(closure){
for(int i in 1..5){
closure(i)
}
}
7.环境
//用groovy语法读取配置文件
def getServerUrl(String str){
def url;
Properties properties = new Properties()
def proFile = file('src/main/filters/'+str+"/config.properties")
if(proFile.canRead()){
properties.load(new FileInputStream(proFile));
if(properties!=null){
url = properties['SERVER2']
}
}
url
}
//签名
buildTypes {
//测试环境,一个域名
debug{
// 数据类型 变量名 变量值
buildConfigField 'String','url',getServerUrl("debug")
//通过buildConfigField放到java中
}
//生产环境 ,另一个域名
release {
buildConfigField 'String','url',getServerUrl("release")
//混淆
minifyEnabled true
signingConfig signingConfigs.release
//包的输出 渠道+时间.apk
android.applicationVariants.all{
variant ->
variant.outputs.all{
def fileName = "${getCurrentTime()}_V${defaultConfig.versionName}_release.apk"
outputFileName = fileName
}
}
}
}
8.打签名包
//签名配置
signingConfigs{
release{
keyAlias 'key0'
keyPassword '123456'
storeFile file('demo.jks')
storePassword '123456'
}
}
9.打多个渠道包(友盟)
打不同的渠道包,投放到不同的应用市场
//多渠道包的code
flavorDimensions "versionCode"
//打多个渠道包,友盟,自己统计,
//1、打不同的渠道包,然后投放到不同的平台或者是应用市场
//2、在java中取不同的值去统计
//最原始的多渠道打包
productFlavors{
xiaomi{
buildConfigField 'String','PLATE_FROM',"\"xiaomi\""
}
qh360{
buildConfigField 'String','PLATE_FROM',"\"qh360\""
}
/* */
baidu{
buildConfigField 'String','PLATE_FROM',"\"baidu\""
}
}
//一键化多渠道打包
productFlavors{
xiaomi{
}
qh360{
}
baidu{
}
}
productFlavors.all {
flavor ->
buildConfigField "String","PLATE_FROM","\"${name}\""
}
}
def getCurrentTime(){
//java中生成当前时间 2021-08-16_21_59_59
return new Date().format("yyyy-MM-dd",TimeZone.getTimeZone("UTC"))
}
边栏推荐
- Summary of php function vulnerabilities
- Anaconda报错:An unexpected error has occurred. Conda has prepared the above report 解决办法
- The learning path of a network security mouse - the basic use of nmap
- Laravel打印执行的SQL语句
- 张量乘积—实验作业
- SQL注入(6)
- 关于我的项目-微信小程序2(uniapp->wx小程序)
- Laravel 登录,中间件和路由分组
- 【泰山众筹】模式为什么一直都这么火热?是有原因的
- [Hello World教程] 使用HBuilder和Uni-app 生成一个简单的微信小程序DEMO
猜你喜欢

树莓派4b安装win11/10过程全教程(附蓝屏inaccessible boot device解决办法)

元宇宙:为何互联网大佬纷纷涉足?元宇宙跟NFT是什么关系?

超级云APP,陪伴您一起成长的软件

VIKINGS: 1 vulnhub walkthrough

关于我的数学建模~

(6) Design of student information management system

Solve the problem that the 5+APP real machine test cannot access the background (same local area network)

借贷记账法下的账户结构、借贷记账法的记账规则、借贷记账法下的账户对应关系与会计分录

The CTF introduction of PHP file contains

修复APP的BUG,热修复的知识点和大厂的相关资料汇总
随机推荐
Pycharm packages the project as an exe file
浅谈性能优化:APP的启动流程分析与优化
mysql 原生语句点滴学习记录
hackmyvm-bunny预排
Offensive and defensive world - novice MISC area 1-12
hackmyvm: again walkthrough
命令执行漏洞
The shooting range that web penetration must play - DVWA shooting range 1 (centos8.2+phpstudy installation environment)
张量乘积—实验作业
2021-09-04 最简单的Golang定时器应用以及最简单的协程入门儿
The CTF introduction of PHP file contains
政府会计的概念、政府会计标准体系、政府会计的特点(会形成小考点)、政府会计要素及其确认和计量、政府预算会计要素、政府财务会计要素
Laravel 的关联模型 及其 预加载多个关联 with使用方法
c语言用栈实现计算中缀表达式
还原最真实、最全面的一线大厂面试题
Activity
成本会计的概念、产品成本核算的要求、产品成本核算的对象与成本项目、产品成本的归集和分配(可能考判断)、产品成本计算方法 (三种:产品的品种(品种法),批次(分批法),步骤(分步法))
xxe of CTF
After Alibaba Cloud sets up domain name resolution redirection, I cannot use Chrome to access it
Syncthing文件同步方案完全攻略(亲测有效)