buildscript {
    ext {
        kotlin_version = '1.8.21'
        ksp_version = "$kotlin_version-1.0.11"
        agp_version = '7.4.2'
        glide_version = '4.15.1'
        // AppGallery Connect plugin versions: https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-sdk-changenotes-0000001058732550
        huawei_agconnect_version = '1.9.1.300'
        abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, 'x86': 3, 'x86_64': 4]
        useCrashlytics = gradle.startParameter.taskNames.any { task -> task.containsIgnoreCase("play") }
        useHms = gradle.startParameter.taskNames.any { task -> task.containsIgnoreCase("huawei") }
    }

    repositories {
        google()
        mavenCentral()

        if (useHms) {
            // HMS (used by some flavors only)
            maven { url 'https://developer.huawei.com/repo/' }
        }
    }

    dependencies {
        classpath "com.android.tools.build:gradle:$agp_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        if (useCrashlytics) {
            // GMS & Firebase Crashlytics (used by some flavors only)
            classpath 'com.google.gms:google-services:4.3.15'
            classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.4'
        }

        if (useHms) {
            // HMS (used by some flavors only)
            classpath "com.huawei.agconnect:agcp:$huawei_agconnect_version"
        }
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()

        if (useHms) {
            // HMS (used by some flavors only)
            maven { url 'https://developer.huawei.com/repo/' }
        }
    }

//    gradle.projectsEvaluated {
//        tasks.withType(JavaCompile) {
//            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
//        }
//    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

tasks.register('clean', Delete) {
    delete rootProject.buildDir
}
