def BUILD_DIR = '../../../../'+System.getenv('BUILD_DIR')+'/app'

def projectVariable(name) {
  /* This function retrieves a variable from the environment and falls back
   * to the Gradle projects's properties (e.g. ~/.gradle/gradle.properties) */
  return System.getenv('ANDROID_'+name) ?: project.findProperty('EPSILON_'+name)
}

def fileIfPath(path) {
  return path ? new File(path) : null
}

buildscript {
  repositories {
    jcenter()
    google()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0'
    classpath 'com.google.gms:google-services:4.2.0'
  }
}

allprojects {
  repositories {
    jcenter()
    google()
  }
  buildDir = BUILD_DIR
}

apply plugin: 'com.android.application'

android {
  compileSdkVersion 29
  defaultConfig {
    applicationId "io.github.omega.simulator"
    minSdkVersion 16
    targetSdkVersion 29
    def (major, minor, patch) = System.getenv('OMEGA_VERSION').toLowerCase().tokenize('.').collect{it.toInteger()}
    versionCode major*1000000 + minor*10000 + patch * 100
    versionName System.getenv('OMEGA_VERSION')
  }
  signingConfigs {
    environment {
      storeFile fileIfPath(projectVariable('SIGNING_STORE_FILE'))
      storePassword projectVariable('SIGNING_STORE_PASSWORD')
      keyAlias projectVariable('SIGNING_KEY_ALIAS')
      keyPassword projectVariable('SIGNING_KEY_PASSWORD')
    }
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt')
      if (projectVariable('SIGNING_STORE_FILE')) {
        signingConfig signingConfigs.environment
      }
    }
  }
  sourceSets{
    main {
      manifest.srcFile 'src/AndroidManifest.xml'
      res.srcDir BUILD_DIR + '/res'
      java.srcDir 'src'
      jniLibs.srcDir BUILD_DIR + '/libs/' + System.getenv('EPSILON_VARIANT')
      assets.srcDir '../assets'
    }
  }
  lintOptions {
    abortOnError false
    checkReleaseBuilds false
  }
}

dependencies {
  implementation fileTree(include: ['*.jar'], dir: 'libs')
  implementation "androidx.appcompat:appcompat:1.0.2"
  implementation "com.google.android.gms:play-services-analytics:16.0.7"
}
