buildscript {
    ext.safeExtGet = { prop, fallback ->
        rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
    }
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        def kotlinVersion = safeExtGet('kotlinVersion', '2.1.20')
        classpath "org.jetbrains.kotlin:kotlin-serialization:${kotlinVersion}"
    }
}

apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'

// RaTeX supports only the React Native New Architecture (Fabric), i.e. RN >= 0.84.
def isNewArchEnabled = project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
if (!isNewArchEnabled) {
    throw new GradleException("ratex-react-native requires the New Architecture (newArchEnabled=true). React Native >= 0.84 enables it by default.")
}

apply plugin: "com.facebook.react"

android {
    compileSdk safeExtGet('compileSdkVersion', 34)
    namespace "io.ratex.rn"

    defaultConfig {
        minSdk safeExtGet('minSdkVersion', 24)
        targetSdk safeExtGet('targetSdkVersion', 34)
    }

    sourceSets {
        main {
            java.srcDirs = [
                'src/main/kotlin',
                "${project.buildDir}/generated/source/codegen/java"
            ]
            jniLibs.srcDirs = ['src/main/jniLibs']
            assets.srcDirs = ['src/main/assets']
            manifest.srcFile 'src/main/AndroidManifest.xml'
        }
    }
}

repositories {
    mavenCentral()
    google()
}

dependencies {
    implementation "com.facebook.react:react-android"
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
}
