// android/build.gradle

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

    ext.blaze_kotlin_version = safeExtGet('kotlinVersion', '1.7.20')

    repositories {
        google()
        gradlePluginPortal()
    }

    dependencies {
        classpath("com.android.tools.build:gradle:8.1.4")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$blaze_kotlin_version"
    }
}

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

android {
    compileSdkVersion safeExtGet('compileSdkVersion', 34)
    namespace "com.blaze.rtnblazesdk"

    def versionJsonFile = file('../package.json')
    def versionJson = new groovy.json.JsonSlurper().parseText(versionJsonFile.text)
    def packageVersion = versionJson.version

    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 24)
        targetSdkVersion safeExtGet('targetSdkVersion', 34)
        versionCode 1
        versionName packageVersion

        consumerProguardFiles "consumer-rules.pro"

        buildConfigField("String", "rtn_sdk_verion", "\"$packageVersion\"")
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }

    lintOptions {
        disable 'GradleCompatible'
    }

    def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
    if (agpVersion.tokenize('.')[0].toInteger() < 8) {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_11
            targetCompatibility JavaVersion.VERSION_11
        }

        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_11.majorVersion
        }
    }

    buildFeatures {
        buildConfig = true
    }
}

repositories {
    google()
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$blaze_kotlin_version"
      
    // noinspection GradleDynamicVersion
    api 'com.facebook.react:react-native:+'

    def blazeSDK = '1.2.13'
    implementation group: "com.blaze", name: "blazesdk", version: "${blazeSDK}"

    // Gson.
    def GsonVersion = "2.10.1"
    implementation "com.google.code.gson:gson:$GsonVersion"
}
