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

def isNewArchitectureEnabled() {
    // To opt-in for the New Architecture, you can either:
    // - Set `newArchEnabled` to true inside the `gradle.properties` file
    // - Invoke gradle with `-newArchEnabled=true`
    // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
    return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

if (isNewArchitectureEnabled()) {
    apply plugin: 'com.facebook.react'
}

android {
    def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
    if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
      namespace "com.rncamerakit"
    }
    compileSdkVersion = 34
    defaultConfig {
        minSdkVersion = 24
        // noinspection ExpiredTargetSdkVersion
        targetSdkVersion = 34
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "arm64-v8a", "x86"
        }
        buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
    }
    lintOptions {
        warning 'InvalidPackage'
    }

    sourceSets {
        main {
            if (isNewArchitectureEnabled()) {
                java.srcDirs += ['src/newarch']
            } else {
                java.srcDirs += ['src/oldarch']
            }
        }
    }
}

dependencies {
    implementation 'com.facebook.react:react-native:+'
    implementation group: 'com.drewnoakes', name: 'metadata-extractor', version: '2.18.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"

    // CameraX core library using the camera2 implementation
    def camerax_version = "1.4.2"
    // The following line is optional, as the core library is included indirectly by camera-camera2
    implementation "androidx.camera:camera-core:${camerax_version}"
    implementation "androidx.camera:camera-camera2:${camerax_version}"
    // If you want to additionally use the CameraX Lifecycle library
    implementation "androidx.camera:camera-lifecycle:${camerax_version}"
    // If you want to additionally use the CameraX VideoCapture library
    // implementation "androidx.camera:camera-video:${camerax_version}"
    // If you want to additionally use the CameraX View class
    implementation "androidx.camera:camera-view:${camerax_version}"
    // If you want to additionally add CameraX ML Kit Vision Integration
    // implementation "androidx.camera:camera-mlkit-vision:${camerax_version}"
    // If you want to additionally use the CameraX Extensions library
    // implementation "androidx.camera:camera-extensions:${camerax_version}"

    implementation 'com.google.mlkit:barcode-scanning:17.3.0'
}
repositories {
    mavenCentral()
}
