// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '2.1.21'
    repositories {
        mavenCentral()
        google()
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.10.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
    compileSdk 35

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 36
        consumerProguardFiles 'proguard-rules.txt'
        externalNativeBuild {
            cmake {
                arguments "-DANDROID_STL=c++_static"
                // In case you need to see the build commands used by CMake, try
                // arguments "-DANDROID_STL=c++_static", "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
                abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a', 'x86_64'
            }
        }
        ndk {
            abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a', 'x86_64'
            stl 'c++_static'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    java {
        toolchain {
            languageVersion.set(JavaLanguageVersion.of(17))
        }
    }

    kotlinOptions {
        jvmTarget = "17"
    }

    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    ndkVersion '23.1.7779620'
    namespace 'ag.boersego.bgjs'
}

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11'
    compileOnly "androidx.annotation:annotation:1.9.1"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    kapt project(path: ':ejecta-v8:v8annotations-compiler')
    api project(path: ':ejecta-v8:v8annotations')
    api 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
}

task distributeDebug() {
    doFirst {
        delete "dist/debug"
        mkdir "dist/debug/jni"
        copy {
            from "build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni"
            into "dist/debug/jni"
        }
    }
}

task distributeRelease {
    doFirst {
        delete "dist/release"
        mkdir "dist/release/jni"
        copy {
            from "build/intermediates/library_jni/release/copyReleaseJniLibsProjectOnly/jni"
            into "dist/release/jni"
        }
    }
}

afterEvaluate {
    copyDebugJniLibsProjectOnly.finalizedBy distributeDebug
    copyReleaseJniLibsProjectOnly.finalizedBy distributeRelease
}