// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        androidXVersion = "1.3.0"
        androidXAnnotation = "1.2.0"
        buildToolsVersion = "29.0.3"
        minSdkVersion = 23
        compileSdkVersion = 33
        targetSdkVersion = 33
        ndkVersion = "22.1.7171670"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:4.2.2')
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // TODO: remove this after closed beta
        classpath 'com.google.gms:google-services:4.3.3'
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
//            url("$rootDir/../node_modules/react-native/android")

            // Replace AAR from original RN with AAR from react-native-v8
            url("$rootDir/../node_modules/react-native-v8/dist")
        }
        maven {
            // prebuilt libv8android.so
            // url("$rootDir/../node_modules/v8-android/dist")
            url("$rootDir/../node_modules/v8-android-jit/dist")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        maven {
            // expo-camera bundles a custom com.google.android:cameraview
            url "$rootDir/../node_modules/expo-camera/android/maven"
        }

        google()
        mavenCentral()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}


// Upgrading  compile SdkVersion and buildToolsVersion of subProjects
 subprojects {
    afterEvaluate {
        project ->
            if (project.hasProperty("android")) {
                android {
                    compileSdkVersion = 31
                    buildToolsVersion = "29.0.3"
                }
            }
    }
}

task importEnvFile {
    def envFile = file("${rootDir.getPath()}/../.env")

    if (envFile.exists()) {
        envFile.readLines().each() {
            if (!it.isEmpty() && !it.startsWith("#")) {
                def (key, value) = it.tokenize('=')
                if (key) {
                    System.properties[key] = (value ? value : '')
                }
            }
        }
    }
}

ext.getEnvValue = { key ->
    if (System.getenv(key)) { // Get var from system env first
        return System.getenv(key)
    } else if (System.getProperty(key)) { // if null, get var from env file
        return System.getProperty(key)
    }
    return "" // if null, return an empty string
}
