plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

// AGP
//com.android.application提供
// 配置安卓工程的构建
android {
    compileSdkVersion 30 // 编译时使用SDK的版本
    //buildToolsVersion "30.0.2" //aapt, packageTool, abd, dx

    // ProductFlavor：产品风味，针对一次Android应用构建的设置
    // defaultConfig默认的产品风味
    defaultConfig {
        applicationId "com.dongnaoedu.gradledemo03" // 应用的身份ID，或者包名，但是此包名非Java类的包名
        applicationIdSuffix "aaa" // 往applicationId加后缀
        minSdkVersion 28 // 最小的支持的Android系统版本
        targetSdkVersion 30 // 针对开发的使用的Android SDK版本，一般compileSdkVersion保持一致
        versionCode 1 // 这个应用的版本号
        versionName "1.0" // 这个应用的版本名称
        //versionNameSuffix '' //versionName后缀

        manifestPlaceholders = [CHANNEL_VALUE: 'dongnao/maniu']

        //testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" // Gradle引擎
    }

    flavorDimensions "channel"/*, "charge"*/ // 维度，就是针对一种类型的产品风味的描述

    // [flavorDimensions]X[productFlavors]x[release,debug]
    // 产品风味的自定义，也就是变种
    productFlavors {
        huawei {
            dimension "channel"
            manifestPlaceholders = [CHANNEL_VALUE: 'huawei']
        }

        free {
            dimension "charge"
        }
//
//        paid {
//            dimension "charge"
//        }
    }

    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                // 遍历所有的产品风味
                productFlavors.each { flavor ->
                    //gradle_v1.0_huawei_release.apk
                    def fileName = "gradle_v${defaultConfig.versionName}_${flavor.manifestPlaceholders.CHANNEL_VALUE}_release.apk"
                    outputFileName = fileName
                }
            }
        }
    }

    // 构建类型： debug, release
    // NamedDomainObjectContainer class类型
    buildTypes {
        release {
//            zipAlignEnabled true// 知否开启 zipAlign
            shrinkResources true // 清理无效资源
            minifyEnabled true // 是否启用代码混淆
            // 指定代码混淆的配置文件
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
//        debug{
//
//        }
//        custom{
//            initWith release
//        }
    }

    // 为每个

    // 配置应用的签名信息
    signingConfigs {
        release {
            storeFile file('key_store.jks')
            storePassword "a123123"
            keyAlias "aaa"
            keyPassword "a123123"
        }
        debug {
            storeFile file('key_store.jks')
            storePassword "a123123"
            keyAlias "aaa"
            keyPassword "a123123"
        }
    }

    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'
}

// 遗留问题：
// 两种维度的产品变种进行组合，如果设置了相同的属性，到底谁的生效