buildscript {
    ext.safeExtGet = {prop, fallback ->
        rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
    }

    def kotlin_version = safeExtGet('kotlinVersion', '2.0.21')

    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:8.7.2")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
    }
}

def reactNativeArchitectures() {
    def value = rootProject.getProperties().get("reactNativeArchitectures")
    return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: "com.facebook.react"

android {
    compileSdkVersion safeExtGet('compileSdkVersion', 35)

    namespace "com.reactnativeencoding"

    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 24)
        targetSdkVersion safeExtGet('targetSdkVersion', 35)

        externalNativeBuild {
            cmake {
                cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
                arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
                abiFilters (*reactNativeArchitectures())
            }
        }
    }

    buildFeatures {
        buildConfig true
        prefab true
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    externalNativeBuild {
        cmake {
            path "../cpp/CMakeLists.txt"
        }
    }

    sourceSets {
        main {
            java.srcDirs += [
                "${project.buildDir}/generated/source/codegen/java"
            ]
            jniLibs.srcDirs += [
                "${project.buildDir}/generated/source/codegen/jni"
            ]
        }
    }
}

repositories {
    mavenCentral()
    google()
}

dependencies {
    implementation "com.facebook.react:react-android" // Set by the React Native Gradle Plugin
}
