plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader("UTF-8") { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) {
    flutterVersionCode = "1"
}

def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) {
    flutterVersionName = "1.0"
}

android {
    namespace = "com.atmob.elec_asst"
    compileSdk = rootProject.ext.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = rootProject.ext.applicationId
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdk = rootProject.ext.minSdkVersion
        targetSdk = rootProject.ext.targetSdkVersion
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName

        ndk {
            //noinspection ChromeOsAbiSupport
            abiFilters "arm64-v8a"
        }
    }

    signingConfigs {
        ting {
            storeFile file("keystore/ting.jks")
            storePassword "ting888"
            keyAlias "ting"
            keyPassword "ting888"
        }
        ling {
            storeFile file("keystore/ling.jks")
            storePassword "ling888"
            keyAlias "ling"
            keyPassword "ling888"
        }
        juan {
            storeFile file("keystore/juan.jks")
            storePassword "juan888"
            keyAlias "juan"
            keyPassword "juan888"
        }
        you {
            storeFile file("keystore/you.jks")
            storePassword "you888"
            keyAlias "you"
            keyPassword "you888"
        }
    }

    buildTypes {
        debug {
            // Note: The debug build type must have the same signing config as the main build type.
            signingConfig signingConfigs.ting
        }
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.ting
        }
    }

    buildFeatures {
        viewBinding true
        dataBinding true
    }

    applicationVariants.configureEach { variant ->
        def date = new Date().format("YYMMddHHmmss")
        variant.outputs.configureEach {
            def fileName = "${defaultConfig.applicationId}" +
                    "-v${defaultConfig.versionName}" +
                    "-${variant.buildType.name}" +
                    "-${date}" +
                    ".apk"
            outputFileName = fileName
        }
    }
}

dependencies {

    //AppCompat
    implementation "androidx.appcompat:appcompat:$rootProject.ext.appcompat_version"

    //ConstraintLayout
    implementation "androidx.constraintlayout:constraintlayout:$rootProject.ext.constraintlayout_version"

    //immersionbar
    implementation "com.geyifeng.immersionbar:immersionbar:$rootProject.ext.immersionbar_version"

    //oaid
    implementation 'extension.oaid:oaid:2.3.0'

    //友盟统计
    implementation 'com.umeng.umsdk:common:9.6.7'
    implementation 'com.umeng.umsdk:asms:1.8.0'
    implementation 'com.umeng.umsdk:apm:1.9.4'

    //渠道包信息读取
    implementation "extra.pack:channel:1.1.0-SNAPSHOT"
}

flutter {
    source = "../.."
}
