plugins {
    id "com.android.application"
    id "kotlin-android"
    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 "br.com.flutterando.yuno"
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    flavorDimensions "default"

    productFlavors {
        dev {
            dimension "default"
            resValue "string", "app_name", "[DEV]YuNO"
            applicationIdSuffix ".dev"
        }

        prod {
            dimension "default"
            resValue "string", "app_name", "YuNO"
        }
    }

    defaultConfig {
        applicationId "br.com.flutterando.yuno"
        minSdkVersion 29
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    splits {
        abi {
            enable true
            reset()
            include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
            universalApk true  
        }
    }

    signingConfigs {
        release {
            keyAlias System.getenv('KEYSTORE_ALIAS')
            keyPassword System.getenv('KEYSTORE_PASSWD')
            storeFile file('key.jks')
            storePassword System.getenv('KEYSTORE_PASSWD')
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
        debug {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {}
