apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: "com.google.firebase.firebase-perf"

crashlytics {
  enableNdk true
}

import com.android.build.OutputFile

project.ext.react = [
  entryFile: "index.js"
]

// up to mono root
apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

/**
 * Use international variant JavaScriptCore
 * International variant includes ICU i18n library and necessary data allowing to use
 * e.g. Date.toLocaleString and String.localeCompare that give correct results
 * when using with locales other than en-US.
 * Note that this variant is about 6MiB larger per architecture than default.
 */
def useIntlJsc = false

android {
  compileSdkVersion 28
  aaptOptions {
    noCompress "tflite"
  }
  defaultConfig {
    applicationId "com.invertase.testing"
    minSdkVersion 18
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    ndk {
      abiFilters "armeabi-v7a", "x86"
    }

    testBuildType System.getProperty('testBuildType', 'debug')
    testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    multiDexEnabled true
  }
  splits {
    abi {
      reset()
      enable enableSeparateBuildPerCPUArchitecture
      universalApk false  // If true, also generate a universal APK
      include "armeabi-v7a", "x86"
    }
  }

  signingConfigs {
    release {
      storeFile file("keystore.jks")
      storePassword "12345678"
      keyAlias "key0"
      keyPassword "12345678"
    }
  }

  buildTypes {
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
      proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
      signingConfig signingConfigs.release
      matchingFallbacks = ['release']
    }
    debug {
      matchingFallbacks = ['debug']
    }
  }

  compileOptions {
    sourceCompatibility 1.8
    targetCompatibility 1.8
  }

  // applicationVariants are e.g. debug, release
  applicationVariants.all { variant ->
    variant.outputs.each { output ->
      // For each separate APK per architecture, set a unique version code as described here:
      // https://developer.android.com/studio/build/configure-apk-splits.html
      def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
      def abi = output.getFilter(OutputFile.ABI)
      if (abi != null) {  // null for the universal-debug, universal-release variants
        output.versionCodeOverride =
          versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
      }
    }
  }

  packagingOptions {
    exclude 'META-INF/proguard/androidx-annotations.pro'
    exclude 'META-INF/-no-jdk.kotlin_module'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    pickFirst '**/armeabi-v7a/libc++_shared.so'
    pickFirst '**/x86/libc++_shared.so'
    pickFirst '**/arm64-v8a/libc++_shared.so'
    pickFirst '**/x86_64/libc++_shared.so'
    pickFirst '**/x86/libjsc.so'
    pickFirst '**/armeabi-v7a/libjsc.so'
  }
}

dependencies {
  implementation fileTree(include: ['*.jar'], dir: 'libs')
  //noinspection GradleDynamicVersion
  implementation 'com.facebook.react:react-native:+'
  //noinspection GradleDynamicVersion
  
  // JSC from node_modules
  if (useIntlJsc) {
    implementation 'org.webkit:android-jsc-intl:+'
  } else {
    implementation 'org.webkit:android-jsc:+'
  }

  /* ------------------------
   *  TESTING SDKS/LIBRARIES
   * ------------------------ */
  implementation(project(path: ':jet')) {
    transitive = false
  }
  androidTestImplementation('com.wix:detox:+') { transitive = true }
  androidTestImplementation 'junit:junit:4.12'
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
  from configurations.compile
  into 'libs'
}

apply plugin: 'com.google.gms.google-services'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
