// android/build.gradle
buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath("com.android.tools.build:gradle:7.2.1")
    }
}

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion safeExtGet('compileSdkVersion', 33)
    buildToolsVersion safeExtGet('buildToolsVersion', '33.0.0')
    
    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 21)
        targetSdkVersion safeExtGet('targetSdkVersion', 33)
        versionCode 1
        versionName "1.0"
        
        // Enable C++ exceptions and add flag to disable __int128
        externalNativeBuild {
            cmake {
              cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all -std=c++17"
              abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
            }
        }
        
        // Set ABIs to compile
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
        }
    }
    
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    
    // Configure CMake
    externalNativeBuild {
        cmake {
            path "./CMakeLists.txt"
        }
    }
    
    // Handle native libs
    packagingOptions {
        pickFirst '**/*.so'
    }
}

dependencies {
    implementation "com.facebook.react:react-native:+"
}