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

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

configurations {
    mapboxRuntimeOnly
    vtmRuntimeOnly
    if (hasModule("hms", true)) hmsRuntimeOnly
    defaultRuntimeOnly
}

dependencies {
    implementation "com.squareup.wire:wire-runtime:$wireVersion"
    implementation "de.hdodenhof:circleimageview:1.3.0"

    implementation project(':fake-signature')
    implementation project(':firebase-dynamic-links')
    implementation project(':firebase-auth-core')
    implementation project(':play-services-ads-core')
    implementation project(':play-services-ads-identifier-core')
    implementation project(':play-services-ads-lite-core')
    implementation project(':play-services-appinvite-core')
    implementation project(':play-services-appset-core')
    implementation project(':play-services-auth-api-phone-core')
    implementation project(':play-services-auth-blockstore-core')
    implementation project(':play-services-auth-workaccount-core')
    implementation project(':play-services-base-core')
    implementation project(':play-services-cast-core')
    implementation project(':play-services-cast-framework-core')
    implementation project(':play-services-conscrypt-provider-core')
    implementation project(':play-services-cronet-core')
    implementation project(':play-services-droidguard-core')
    implementation project(':play-services-fido-core')
    implementation project(':play-services-fitness-core')
    implementation project(':play-services-gmscompliance-core')
    implementation project(':play-services-location-core')
    implementation project(':play-services-location-core-base')
    implementation project(':play-services-oss-licenses-core')
    implementation project(':play-services-panorama-core')
    implementation project(':play-services-pay-core')
    implementation project(':play-services-recaptcha-core')
    implementation project(':play-services-safetynet-core')
    implementation project(':play-services-tapandpay-core')
    implementation project(':play-services-threadnetwork-core')
    implementation project(':play-services-vision-core')
    implementation project(':play-services-wearable-core')

    implementation project(':play-services-core-proto')

    implementation project(':play-services-core:microg-ui-tools') // deprecated
    implementation project(':play-services-base-core-package')
    implementation project(':play-services-api')

    implementation project(':play-services-appinvite')
    implementation project(':play-services-auth-base')
    implementation project(':play-services-auth')
    implementation project(':play-services-clearcut')
    implementation project(':play-services-drive')
    implementation project(':play-services-games')
    implementation project(':play-services-maps')
    implementation project(':play-services-measurement-base')
    implementation project(':play-services-places')
    implementation project(':play-services-recaptcha')
    implementation project(':play-services-safetynet')
    implementation project(':play-services-tasks-ktx')
    implementation project(':play-services-fitness')

    mapboxRuntimeOnly project(':play-services-maps-core-mapbox')
    vtmRuntimeOnly project(':play-services-maps-core-vtm')
    defaultRuntimeOnly project(':play-services-location-core-provider')

    if (hasModule("nearby", true)) runtimeOnly project(':play-services-nearby-core-package')
    if (hasModule("hms", false)) hmsRuntimeOnly project(':play-services-maps-core-hms')

    // AndroidX UI
    implementation "androidx.multidex:multidex:$multidexVersion"
    implementation "androidx.appcompat:appcompat:$appcompatVersion"
    implementation "androidx.mediarouter:mediarouter:$mediarouterVersion"
    implementation "androidx.preference:preference-ktx:$preferenceVersion"
    implementation "androidx.webkit:webkit:$webkitVersion"

    // Material Components
    implementation "com.google.android.material:material:$materialVersion"

    // Compose
    def composeBom = platform('androidx.compose:compose-bom:2024.04.00')
    implementation composeBom
    implementation 'androidx.compose.material3:material3'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    debugImplementation 'androidx.compose.ui:ui-tooling'
    implementation 'androidx.activity:activity-compose:1.8.2'

    // Navigation
    implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
    implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"

    implementation "com.android.volley:volley:$volleyVersion"

    implementation "androidx.lifecycle:lifecycle-service:$lifecycleVersion"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
}

android {
    namespace "com.google.android.gms"

    compileSdkVersion androidCompileSdk
    buildToolsVersion "$androidBuildVersionTools"

    buildFeatures {
        buildConfig = true
        dataBinding = true
        compose true
    }

    defaultConfig {
        versionName version
        versionCode appVersionCode

        minSdkVersion androidMinSdk
        targetSdkVersion androidTargetSdk

        multiDexEnabled true
        multiDexKeepProguard file('multidex-keep.pro')

        manifestPlaceholders = [appLabel:"@string/gms_app_name"]
        resValue "string", "package_id", "com.google.android.gms"

        buildConfigField "String", "SAFETYNET_KEY", "\"${localProperties.get("safetynet.key", "")}\""
        buildConfigField "String", "RECAPTCHA_SITE_KEY", "\"${localProperties.get("recaptcha.siteKey", "")}\""
        buildConfigField "String", "RECAPTCHA_SECRET", "\"${localProperties.get("recaptcha.secret", "")}\""
        buildConfigField "String", "RECAPTCHA_ENTERPRISE_PROJECT_ID", "\"${localProperties.get("recaptchaEnterpreise.projectId", "")}\""
        buildConfigField "String", "RECAPTCHA_ENTERPRISE_SITE_KEY", "\"${localProperties.get("recaptchaEnterpreise.siteKey", "")}\""
        buildConfigField "String", "RECAPTCHA_ENTERPRISE_API_KEY", "\"${localProperties.get("recaptchaEnterpreise.apiKey", "")}\""

        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }
    }

    composeOptions {
        kotlinCompilerExtensionVersion = "1.5.10"
    }

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

    lintOptions {
        disable 'MissingTranslation', 'GetLocales', 'InvalidPackage', 'BatteryLife', 'ImpliedQuantity', 'MissingQuantity', 'InvalidWakeLockTag', 'UniquePermission'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions = ['maps', 'target']
    productFlavors {
        "default" {
            dimension 'target'
        }
        "huawei" {
            dimension 'target'
            versionNameSuffix "-hw"
        }
        "huaweilh" {
            dimension 'target'
            versionNameSuffix "-lh"
            versionCode appVersionCode - 1000
            matchingFallbacks = ['huawei']
        }
        "user" {
            dimension 'target'
            applicationId = "org.microg.gms"
            versionNameSuffix "-user"
            manifestPlaceholders = [appLabel:"@string/limited_services_app_name"]
            matchingFallbacks = ['default']
            resValue "string", "package_id", "org.microg.gms"
        }
        "hms" {
            dimension 'maps'
        }
        "mapbox" {
            dimension 'maps'
        }
        "vtm" {
            dimension 'maps'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = 1.8
    }

    packagingOptions {
        exclude 'META-INF/ASL2.0'
        jniLibs {
            useLegacyPackaging 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(version.length()) + ".apk"
    }
}
