plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    namespace 'com.madlonkay.orgro'
    compileSdk flutter.compileSdkVersion
    // We set this to match what is expected by binaries we compile at build time in F-Droid:
    // https://github.com/jerson/openpgp-mobile/blob/0e5e05ca4b7863fb82c2c5932e802ed9c1ab929d/Makefile.android#L2
    ndkVersion '28.0.13004108'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = '17'
    }

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

    defaultConfig {
        applicationId "com.madlonkay.orgro"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutter.versionCode
        versionName flutter.versionName
        // No need to list base locale (en)
        resourceConfigurations += ['en_US', 'en_GB', 'ja', 'uk', 'de', 'ru']
        manifestPlaceholders += [
            displayName: '@string/app_name',
            appLinkHost: '@string/app_link_host'
        ]
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix '.debug'
            manifestPlaceholders += [
                displayName: '@string/app_name_debug',
                appLinkHost: '@string/app_link_host_debug'
            ]
        }
        profile {
            // TODO(aaron): Remove temporary workaround for
            // https://github.com/flutter/flutter/issues/169215
            //
            // applicationIdSuffix '.profile'
            manifestPlaceholders += [
                displayName: '@string/app_name_profile',
                appLinkHost: '@string/app_link_host_profile'
            ]
        }
        release {
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2'
}
