//配置当前Module构建属性，如果说声明的是com.android.application，表示我生成的是apk文件
// 如果说声明的是com.android.plugin，表示我生成的是aar文件，或是被依赖文件
apply plugin: 'com.android.application'
apply from: 'config.gradle'
//android{}表示当前针对android平台，针对当前module项目构建配置选项
android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.mn.gradledemo"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        buildConfigField "String","CONFIG_TAG2","\"${sever}\""
        buildConfigField "String","DATA_SOURCE","\"${dataSource}\""
        ndk{
            abiFilters 'armeabi','x86','armeabi-v8a'
        }
    }

    signingConfigs{
        release{
            keyAlias 'key0'
            keyPassword '123456'
            storeFile file('demo.jks')
            storePassword '123456'
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            android.applicationVariants.all{
                variant ->
                    variant.outputs.all{
                        def fileName = "${getCurrentTime()}_V${defaultConfig.versionName}_release.apk"
                        outputFileName = fileName
                    }
            }
        }
    }
}

static def getCurrentTime(){
    return new Date().format("yyyy-MM-dd",TimeZone.getTimeZone("UTC"))
}
dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}

task stringText{
    //使用def关键字
    def str1 = "shuangyinhao"
    def str2='danyinhao'
    //println(str1+str2)
    println("woshi--${str1}")
}

task list{
    //定义集合
    def list=[1,2,3,4,5,6]
    def weekList=["One","Two","Three","Four","Five","Six","Seven"]

    println(list[0])
    println(weekList[0])
    weekList.each{
        println it
    }
}

task map{
    def map = ['name':'jack','age':19]
    println map['name']
    map.each {
        println "Key:${it.key},value:${it.value}"
    }
}

task method{
    def a =  methodA(2,3)
    println a
}

//定义一个方法
def methodA(int a,int b){
    //println a+b
    //groovy语法中默认将函数的最后一行作为结果返回
    a + b
}

task javaBean{
    Student student = new Student();
    student.name="groovy"
    student.age=18
    student.setName("lily")
    student.setAge(28)
    println "nianling:${student.age}"
}

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
    }
}

//闭包的概念
task closure{
    mEach{
        println it
    }

    mEachWithParams{m,n -> //m,n ->将闭包的参数和主体区分离开来
        println "${m} is ${n}"
    }
}

def mEach(closure){
    for(int i in 1..5){
        closure(i)
    }
}

def mEachWithParams(closure){
    def map=['name':'groovy','age':10]
    map.each {
        closure(it.key,it.value)
    }
}