apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-parcelize'

apply from: "../instance-build.gradle"

def getGitSha = {
    def stdout = new ByteArrayOutputStream()
    try {
        exec {
            commandLine 'git', 'rev-parse', '--short', 'HEAD'
            standardOutput = stdout
        }
    } catch (Exception e) {
        return "unknown"
    }
    return stdout.toString().trim()
}

android {
    compileSdkVersion 33
    defaultConfig {
        applicationId 'net.accelf.yuito'
        minSdkVersion 21
        targetSdkVersion 31
        versionCode 50
        versionName '4.4.0'
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true

        resValue "string", "app_name", APP_NAME

        buildConfigField("String", "CUSTOM_LOGO_URL", "\"$CUSTOM_LOGO_URL\"")
        buildConfigField("String", "CUSTOM_INSTANCE", "\"$CUSTOM_INSTANCE\"")
        buildConfigField("String", "SUPPORT_ACCOUNT_URL", "\"$SUPPORT_ACCOUNT_URL\"")

        kapt {
            arguments {
                arg("room.schemaLocation", "$projectDir/schemas")
            }
        }
    }
    signingConfigs {
        debug {
            storeFile file('../debug.keystore')
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles 'proguard-rules.pro'
        }
        debug {
            signingConfig signingConfigs.debug
        }
    }

    flavorDimensions "color"
    productFlavors {
        blue {}
        green {
            resValue "string", "app_name", APP_NAME + " Test"
            applicationIdSuffix ".test"
            versionNameSuffix "-" + getGitSha()
        }
    }

    lintOptions {
        disable 'MissingTranslation'
    }
    buildFeatures {
        viewBinding true
    }
    testOptions {
        unitTests {
            returnDefaultValues = true
            includeAndroidResources = true
        }
    }
    sourceSets {
        androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
    }

    packagingOptions {
        // Exclude unneeded files added by libraries
        exclude 'LICENSE_OFL'
        exclude 'LICENSE_UNICODE'
    }
    bundle {
        language {
            // bundle all languages in every apk so the dynamic language switching works
            enableSplit = false
        }
    }
    kotlinOptions {
        freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
    }
}

repositories {
    maven {
        url 'https://maven.accelf.net/'
    }
}

// library versions are in PROJECT_ROOT/gradle/libs.versions.toml
dependencies {
    implementation libs.kotlinx.coroutines.android
    implementation libs.kotlinx.coroutines.rx3

    implementation libs.bundles.androidx
    implementation libs.bundles.room
    kapt libs.androidx.room.compiler

    implementation libs.android.material

    implementation libs.gson

    implementation libs.bundles.retrofit
    implementation libs.networkresult.calladapter

    implementation libs.bundles.okhttp

    implementation libs.conscrypt.android

    implementation libs.bundles.glide
    kapt libs.glide.compiler

    implementation libs.bundles.rxjava3

    implementation libs.bundles.autodispose

    implementation libs.bundles.dagger
    kapt libs.bundles.dagger.processors

    implementation libs.sparkbutton

    implementation libs.photoview

    implementation libs.bundles.material.drawer
    implementation libs.material.typeface, {
        artifact {
            type = "aar"
        }
    }

    implementation libs.image.cropper

    implementation libs.bundles.filemojicompat

    implementation libs.bouncycastle
    implementation libs.unified.push

    testImplementation libs.androidx.test.junit
    testImplementation libs.robolectric
    testImplementation libs.bundles.mockito
    testImplementation libs.mockwebserver
    testImplementation libs.androidx.core.testing
    testImplementation libs.kotlinx.coroutines.test
    testImplementation libs.androidx.work.testing

    androidTestImplementation libs.espresso.core
    androidTestImplementation libs.androidx.room.testing
    androidTestImplementation libs.androidx.test.junit

    implementation libs.accelfeaster
    implementation libs.jsoup
}
