/*
 * SPDX-FileCopyrightText: 2015 microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.squareup.wire'

android {
    namespace "com.android.vending"
    compileSdkVersion androidCompileSdk
    buildToolsVersion "$androidBuildVersionTools"

    defaultConfig {
        versionName vendingAppVersionName
        versionCode vendingAppVersionCode
        minSdkVersion androidMinSdk
        targetSdkVersion androidTargetSdk

        multiDexEnabled true
    }

    buildTypes {
        debug {
            postprocessing {
                removeUnusedCode true
                removeUnusedResources false
                obfuscate false
                optimizeCode false
                proguardFile 'proguard-rules.pro'
            }
        }
        release {
            postprocessing {
                removeUnusedCode true
                removeUnusedResources true
                obfuscate false
                optimizeCode true
                proguardFile 'proguard-rules.pro'
            }
        }
    }

    flavorDimensions = ['target']
    productFlavors {
        "default" {
            dimension 'target'
        }
        "huawei" {
            dimension 'target'
            versionNameSuffix "-hw"
        }
        "huaweilh" {
            dimension 'target'
            versionNameSuffix "-lh"
            versionCode vendingAppVersionCode - 1000
            matchingFallbacks = ['huawei']
        }
    }

    sourceSets {
        main {
            java {
                srcDirs += "build/generated/source/proto/main/java"
            }
        }
    }


    buildFeatures {
        aidl = true
        buildConfig = true
        compose true
    }

    lintOptions {
        disable 'MissingTranslation', 'GetLocales'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = 1.8
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.5.10'
    }
}

dependencies {
    implementation project(':fake-signature')
    implementation project(':play-services-auth')
    implementation project(':play-services-base-core')
    implementation project(':play-services-core-proto')

    implementation "com.squareup.wire:wire-runtime:$wireVersion"
    implementation "com.squareup.wire:wire-grpc-client:$wireVersion"

    implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
    implementation "io.ktor:ktor-client-core:$ktorVersion"
    implementation "io.ktor:ktor-client-okhttp:$ktorVersion"

    implementation "androidx.webkit:webkit:$webkitVersion"


    //compose
    implementation platform('androidx.compose:compose-bom:2022.10.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.material3:material3'
    implementation 'androidx.compose.animation:animation-graphics'
    implementation 'androidx.activity:activity-compose:1.7.2'
    implementation("io.coil-kt:coil-compose:2.4.0")
    implementation("io.coil-kt:coil-svg:2.2.2")
    implementation "com.google.android.material:material:$materialVersion"
    implementation "com.google.accompanist:accompanist-systemuicontroller:0.28.0"

    implementation 'androidx.compose.ui:ui-tooling-preview'
    debugImplementation 'androidx.compose.ui:ui-tooling'

    // Coil (image loading)
    implementation("io.coil-kt:coil-compose:2.7.0")

    //droidguard
    implementation project(':play-services-droidguard')
    implementation project(':play-services-tasks-ktx')

    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutineVersion"

    //androidx
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
    implementation "androidx.core:core-ktx:$coreVersion"
    implementation "androidx.appcompat:appcompat:$appcompatVersion"
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
    implementation "androidx.preference:preference-ktx:$preferenceVersion"

    // tink
    implementation "com.google.crypto.tink:tink-android:$tinkVersion"

    // multidex
    implementation "androidx.multidex:multidex:$multidexVersion"
}

wire {
    kotlin {
        javaInterop = true
    }
}

if (file('user.gradle').exists()) {
    apply from: 'user.gradle'
}

android.applicationVariants.all { variant ->
    variant.outputs.each { output ->
        output.outputFileName = variant.applicationId + "-" + variant.versionCode + variant.versionName.substring(vendingAppVersionName.length()) + ".apk"
    }
}
