plugins {
    alias(libs.plugins.android.application)
}

android {
    namespace 'com.unibuy.smartdevice'
    compileSdk 35

    defaultConfig {
        applicationId "com.unibuy.smartdevice"
        minSdk 21
        targetSdk 34
        versionCode 12
        versionName "1_1_${versionCode}"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    // 設定不同場域
    flavorDimensions "app_type"

    productFlavors {
        S_12_XY_U_Standard_ {
            dimension "app_type"
            versionCode 8
            versionName "10_0${versionCode}_2_R"
        }
    }

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

    // 自定義打包檔案名稱，包含版本號
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def versionCode = variant.versionCode
            def versionName = variant.versionName
            def flavor = variant.productFlavors[0].name
            def buildType = variant.buildType.name

            // 設定打包檔案名稱：app-<flavor>-<versionName>-<buildType>.apk
            output.outputFileName = "app-${flavor}-${versionName}-${buildType}.apk"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    buildFeatures {
        viewBinding true
    }

    packaging {
        resources {
            excludes += ['META-INF/INDEX.LIST', 'META-INF/io.netty.versions.properties']
        }
    }
}

dependencies {
    implementation libs.appcompat
    implementation libs.material
    implementation libs.activity
    implementation libs.constraintlayout
    implementation libs.work.runtime
    testImplementation libs.junit
    androidTestImplementation libs.ext.junit
    androidTestImplementation libs.espresso.core

    annotationProcessor libs.compiler
    implementation libs.usb.serial.for.android
    implementation libs.android.serialport
    implementation libs.glide
    implementation libs.media3.exoplayer
    implementation libs.media3.ui
    implementation libs.tsnackBar

    implementation 'com.blankj:utilcodex:1.31.1'
    implementation 'com.hivemq:hivemq-mqtt-client:1.3.3'
    implementation 'io.netty:netty-codec-http:4.1.94.Final'
    implementation 'io.netty:netty-handler:4.1.94.Final'
    implementation 'com.google.code.gson:gson:2.10.1'
}
