apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'yac-engine'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-parcelize'

android {
    compileSdkVersion build_versions.compileSdkVersion

    defaultConfig {
        applicationId rootProject.ext.android.applicationId
        minSdkVersion build_versions.minSdkVersion
        targetSdkVersion build_versions.targetSdkVersion
        versionCode rootProject.ext.android.versionCode
        versionName rootProject.ext.android.versionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        manifestPlaceholders = [qqappid: "101923771"]

        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
    }
    signingConfigs {
        production {
            storeFile file("shenghuoquan-b.jks")
            keyAlias 'shenghuoquan_key'
            keyPassword 'shenghuoquan000'
            storePassword 'shenghuoquan000'
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }
    buildTypes {
        debug {
            //不混淆
            minifyEnabled false
            //Zipalign优化
            zipAlignEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.production
        }
        release {
            //混淆
            minifyEnabled true
            //Zipalign优化
            zipAlignEnabled true
            //移除无用的resource文件
            shrinkResources true
            signingConfig signingConfigs.production
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    outputFileName = "merchant-b-${variant.name}-${defaultConfig.versionName}-${defaultConfig.versionCode}.apk"
                }
            }
        }
    }
    flavorDimensions "default"
    productFlavors {
        dev {//开发
            dimension "default"
            applicationId rootProject.ext.android.applicationTestId
            buildConfigField("String", "API_URL", rootProject.ext.buildParams.dev.API_URL)
            buildConfigField("String", "PROVIDER_NAME", '\"' + rootProject.ext.android.applicationTestId + ".fileprovider" + '\"')
            manifestPlaceholders = [
                    app_name      : "商家版开发",
                    application_id: rootProject.ext.android.applicationTestId,
                    amap_key      : rootProject.ext.amap.amap_debug_key,
            ]
        }
        beta {//测试
            dimension "default"
            applicationId rootProject.ext.android.applicationTestId
            buildConfigField("String", "API_URL", rootProject.ext.buildParams.test.API_URL)
            buildConfigField("String", "PROVIDER_NAME", '\"' + rootProject.ext.android.applicationTestId + ".fileprovider" + '\"')
            manifestPlaceholders = [
                    app_name      : "商家版测试",
                    application_id: rootProject.ext.android.applicationTestId,
                    amap_key      : rootProject.ext.amap.amap_debug_key,
            ]
        }
        prod {//生产
            dimension "default"
            applicationId rootProject.ext.android.applicationId
            buildConfigField("String", "API_URL", rootProject.ext.buildParams.prod.API_URL)
            buildConfigField("String", "PROVIDER_NAME", '\"' + rootProject.ext.android.applicationId + ".fileprovider" + '\"')
            manifestPlaceholders = [
                    app_name      : "生活圈商家版",
                    application_id: rootProject.ext.android.applicationId,
                    amap_key      : rootProject.ext.amap.amap_release_key,
            ]
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    kapt {
        generateStubs = true
    }
    buildFeatures {
        viewBinding true
        dataBinding true
    }
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    // kotlin实现MVVM框架之使用DataBinding之unresolved reference: BR解决办法
    kapt "com.android.databinding:compiler:4.0.1"
    rootProject.ext.dependencies.other.each {
        implementation project(it)
    }
    if (!rootProject.ext.android.isApplication) {
        implementation project(":Components:BDemo")
        implementation project(":Components:BManagerCenter")
        implementation project(":Components:BGoods")
        implementation project(":Components:BXBridBusiness")
        implementation project(":Components:BRoot")
        implementation project(":Components:BSetting")
        implementation project(":Components:BGeneralBusiness")
        implementation project(":Components:BUserOrder")
        implementation project(":Components:BMediator")
    }
    implementation rootProject.ext.dependencies.privateImplementation
    testImplementation rootProject.ext.dependencies.testImplementation
    androidTestImplementation rootProject.ext.dependencies.androidTestImplementation
}