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

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

def getExtOrDefault(name, defaultValue) {
    return rootProject.ext.has(name) ? rootProject.ext.get(name) : defaultValue
}

android {
    namespace "com.margelo.nitro.net"
    ndkVersion getExtOrDefault("ndkVersion", "27.1.12297006")
    compileSdkVersion getExtOrDefault('compileSdkVersion', 35)

    defaultConfig {
        minSdkVersion getExtOrDefault('minSdkVersion', 21)
        targetSdkVersion getExtOrDefault('targetSdkVersion', 35)
        buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "false" // Default to false, app will override if needed

        externalNativeBuild {
            cmake {
                cppFlags "-fexceptions", "-frtti", "-std=c++20"
                arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
                abiFilters (*reactNativeArchitectures())
            }
        }
    }

  buildFeatures {
    buildConfig true
    prefab true
  }

  sourceSets {
    main {
      jniLibs.srcDirs += ['libs']
    }
  }

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

    buildTypes {
        release {
            minifyEnabled false
        }
    }

    packagingOptions {
        excludes += [
            "**/libc++_shared.so",
            "**/libjsi.so",
            "**/libreactnativejni.so",
            "**/libreact_nativemodule_core.so",
            "**/libturbomodulejsijni.so"
        ]
    }
}

dependencies {
    implementation "com.facebook.react:react-native:+"
    implementation project(':react-native-nitro-modules')
}

// Apply the Nitrogen-generated Gradle file
apply from: "../nitrogen/generated/android/RustCNet+autolinking.gradle"
