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

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

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

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

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 33

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    kotlinOptions {
        jvmTarget = '11'
    }

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

    defaultConfig {
        applicationId "guru.core.uiux.demo"
        minSdkVersion 23
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName

        multiDexEnabled true
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
        }
    }

    signingConfigs {
        releaseConfig {
            if (project.hasProperty('releaseStoreFile')) {
                storeFile file(releaseStoreFile)
            } else {
                storeFile file('keystore')
            }
            if (project.hasProperty('releaseStorePassword')) {
                storePassword releaseStorePassword
            } else {
                storePassword 'password'
            }
            if (project.hasProperty('releaseKeyAlias')) {
                keyAlias releaseKeyAlias
            } else {
                keyAlias 'alias'
            }
            if (project.hasProperty('releaseKeyPassword')) {
                keyPassword releaseKeyPassword
            } else {
                keyPassword 'password'
            }
        }

        debugConfig {
            storeFile file(debugStoreFile)
            storePassword debugStorePassword
            keyAlias debugKeyAlias
            keyPassword debugKeyPassword
        }

        profileConfig {
            storeFile file(debugStoreFile)
            storePassword debugStorePassword
            keyAlias debugKeyAlias
            keyPassword debugKeyPassword
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.releaseConfig
            shrinkResources true
            minifyEnabled true
            zipAlignEnabled true
            debuggable false
            //proguard
            proguardFiles fileTree(dir: 'proguards', include: '*.pro').asList().toArray()
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.installreferrer:installreferrer:2.2'
    implementation "androidx.annotation:annotation:1.3.0"
    implementation 'androidx.multidex:multidex:2.0.1'
}