import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
    ext.kotlin_version = '2.1.20'
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        // We use 8.6.0 to match your current project
        classpath "com.android.tools.build:gradle:8.6.0"
        classpath "com.google.gms:google-services:4.4.2"
        classpath "com.google.firebase:firebase-crashlytics-gradle:3.0.4"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

rootProject.buildDir = "../build"

subprojects {
    // Force set the build directory
    project.buildDir = "${rootProject.buildDir}/${project.name}"

    // The logic to force SDK 35
    afterEvaluate { project ->
        if (project.hasProperty('android')) {
            project.android {
                // Force compileSdk to 35 for all plugins
                compileSdk = 35
                buildToolsVersion = "35.0.0"

                // Ensure namespace is set for older plugins
                if (namespace == null) {
                    namespace project.group
                }
            }

            // CRITICAL: Disable the metadata check that forces SDK 36
            project.tasks.withType(com.android.build.gradle.internal.tasks.CheckAarMetadataTask).configureEach {
                enabled = false
            }
        }
    }
}

// Move this OUTSIDE of any afterEvaluate blocks
subprojects {
    project.evaluationDependsOn(":app")
}

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