plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'kotlin-android-extensions'
}

def releaseTime() {
    return new Date().format("yyyyMMddHHmm", TimeZone.getTimeZone("GMT+08:00"))
}

android {
    signingConfigs {
        config {
            keyAlias 'pass'
            keyPassword '210419'
            storeFile file('pass.jks')
            storePassword '210419'
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }

    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    compileSdkVersion rootProject.ext.android["compileSdkVersion"]

    defaultConfig {
        applicationId rootProject.ext.android["applicationId"]
        minSdkVersion rootProject.ext.android["minSdkVersion"]
        targetSdkVersion rootProject.ext.android["targetSdkVersion"]
        versionCode rootProject.ext.android["versionCode"]
        versionName rootProject.ext.android["versionName"]
        multiDexEnabled true
        flavorDimensions "CHANNEL_VALUE"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
        debug {
            signingConfig signingConfigs.config
        }
    }

    productFlavors {

        text_product {
            applicationId rootProject.ext.android.applicationId
            manifestPlaceholders = [CHANNEL_VALUE: "企业端(测试)"]

            buildConfigField "String", "BASE_URL", "\"http://pass.dahehuoyun.com:8091/\""
            buildConfigField "String", "BASE_HEAD_URL", "\"http://47.104.167.116:8080/guns/gunsApi/kaptcha/\""
            buildConfigField "boolean", "isTest", "true"
            //APP名称，可以在androidMainfest中引用
//            resValue "string", "appName", "审核测试"
        }
        sign_product {
            applicationId rootProject.ext.android.applicationId
            manifestPlaceholders = [CHANNEL_VALUE: "企业端"]
            buildConfigField "String", "BASE_URL", "\"http://pass.dahehuoyun.com:8091/\""
            buildConfigField "String", "BASE_HEAD_URL", "\"http://47.104.167.116:8080/guns/gunsApi/kaptcha/\""
            buildConfigField "boolean", "isTest", "false"
//            resValue "string", "appName", "审核"
        }
    }
    productFlavors.all { flavor ->
        flavor.manifestPlaceholders = [CHANNEL_VALUE: name]
    }

    android.applicationVariants.all { variant ->
        variant.outputs.all {
//            println("======="+variant.productFlavors[0].properties.get("resValues").getAt("appName").properties.get("value"))
//            println("======="+variant.productFlavors[0].properties.get("buildConfigFields").getAt("isTest").properties.get("value"))
//            println("+++++"+variant.productFlavors[0].name)
            //获取渠道名称
            def  isText = variant.productFlavors[0].properties.get("buildConfigFields").getAt("isTest").properties.get("value")
            def appName = null
            if (isText=="true") {
                appName = '企业端测试_'
            }else{
                appName = '企业端正式_'
            }
            outputFileName =appName+"${variant.buildType.name}_${defaultConfig.versionName}_${releaseTime()}.apk"

        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'


    implementation project(path: ':mylibrary')
    implementation project(path: ':keybordlib')
}