def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

buildscript {
  // The Android Gradle plugin is only required when opening the android folder stand-alone.
  // This avoids unnecessary downloads and potential conflicts when the library is included as a
  // module dependency in an application project.
  if (project == rootProject) {
    repositories {
      google()
      jcenter()
    }

    dependencies {
      //noinspection GradleDependency
      classpath("com.android.tools.build:gradle:3.5.2")
    }
  }
}

apply plugin: 'com.android.library'

android {
  compileSdkVersion safeExtGet('compileSdkVersion', 28)
  buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')

  defaultConfig {
    minSdkVersion safeExtGet('minSdkVersion', 16)
    targetSdkVersion safeExtGet('targetSdkVersion', 28)
  }

  flavorDimensions "react-native-camera"

  productFlavors {
    general {
      dimension "react-native-camera"
    }
    mlkit {
      dimension "react-native-camera"
    }
  }

  sourceSets {
    main {
      java.srcDirs = ['src/main/java']
    }
    general {
      java.srcDirs = ['src/general/java']
    }
    mlkit {
      java.srcDirs = ['src/mlkit/java']
    }
  }

  lintOptions {
    abortOnError false
    warning 'InvalidPackage'
  }

  packagingOptions {
    exclude 'META-INF/androidx.exifinterface_exifinterface.version'
    exclude 'META-INF/proguard/androidx-annotations.pro'
  }
}

repositories {
  google()
  jcenter()
  mavenCentral()
  maven { url "https://jitpack.io" }
  maven {
    // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
    url "$rootDir/../node_modules/react-native/android"
  }
}

dependencies {
  def googlePlayServicesVisionVersion = safeExtGet('googlePlayServicesVisionVersion', safeExtGet('googlePlayServicesVersion', '17.0.2'))

  implementation 'com.facebook.react:react-native:+'
  implementation "com.google.zxing:core:3.3.3"
  implementation "com.drewnoakes:metadata-extractor:2.11.0"
  generalImplementation "com.google.android.gms:play-services-vision:$googlePlayServicesVisionVersion"
  implementation "androidx.exifinterface:exifinterface:1.0.0"
  implementation "androidx.annotation:annotation:1.0.0"
  implementation "androidx.legacy:legacy-support-v4:1.0.0"
  mlkitImplementation "com.google.firebase:firebase-ml-vision:${safeExtGet('firebase-ml-vision', '19.0.3')}"
  mlkitImplementation "com.google.firebase:firebase-ml-vision-face-model:${safeExtGet('firebase-ml-vision-face-model', '17.0.2')}"
}
