apply plugin: 'com.android.application'

def getCommitHash = { ->
    try {
        def stdout = new ByteArrayOutputStream()
        exec {
            commandLine 'git', 'rev-parse', '--short', 'master'
            standardOutput = stdout
        }
        return stdout.toString().trim()
    }
    catch (ignored) {
        return null
    }
}

def properties = new Properties()
def inputStream = project.rootProject.file('local.properties').newDataInputStream()
properties.load(inputStream)

android {
    signingConfigs {
        donmor {
            storeFile file(properties.getProperty('keyFile'))
            storePassword properties.getProperty('signPassword')
            keyAlias = properties.getProperty('keyAlias')
            keyPassword properties.getProperty('signPassword')
        }
    }
    compileSdk 34
    defaultConfig {
        applicationId "top.donmor.tiddloid"
        minSdkVersion 21
        targetSdkVersion 34
        multiDexEnabled true
        versionCode 48
        versionName "2.5.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.donmor
        }
        debug {
            versionNameSuffix "@" + getCommitHash()
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.donmor
        }
    }
    namespace 'top.donmor.tiddloid'
    applicationVariants.configureEach { variant ->
        variant.resValue "string", "versionName", variant.versionName
    }
}
dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.core:core:1.12.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.11.0'
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    implementation 'com.pixplicity.sharp:sharp:1.1.3@aar'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation "androidx.multidex:multidex:2.0.1"
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:runner:1.5.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}