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

def getGitHash = { ->
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-parse', '--short', 'HEAD'
        standardOutput = stdout
        ignoreExitValue = true
    }
    return stdout.toString().trim()
}

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

android {
    namespace = "com.aliucord.installer"
    compileSdk = 34

    defaultConfig {
        applicationId "com.aliucord.installer"
        minSdk = 21
        //noinspection OldTargetApi
        targetSdk = 29
        versionCode = flutter.versionCode
        versionName = flutter.versionName

        buildConfigField "String", "GIT_REVISION", "\"${getGitHash()}\""
    }

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

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

    buildFeatures.buildConfig = true
}

flutter {
    source '../..'
}

dependencies {
    //noinspection GradleDependency
    implementation 'org.bouncycastle:bcpkix-jdk15on:1.65'

    implementation fileTree(include: '*.aar', dir: './libs')
}
