apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
// Enable this manually only to avoid slowing down the build
//apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'kotlin-android'
apply plugin: 'okreplay'

String getFabricApiKey() {
  String keyName = 'ELIFUT_FABRIC_API_KEY'
  String env = System.getenv(keyName)
  if (env != null) {
    return env
  } else if (project.hasProperty(keyName)) {
    return project.property(keyName)
  } else {
    return "fabric-api-key-not-set"
  }
}

android {
  compileSdkVersion project.ext.compileSdkVersion
  buildToolsVersion project.ext.buildToolsVersion

  defaultConfig {
    applicationId "com.elifut"
    minSdkVersion project.ext.minSdkVersion
    targetSdkVersion project.ext.targetSdkVersion
    versionCode project.ext.versionCode
    versionName project.ext.versionName
    manifestPlaceholders = [fabricApiKey: getFabricApiKey()]
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }

  sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
    androidTest.java.srcDirs += 'src/androidTest/kotlin'
    debug {
      manifest.srcFile 'src/debug/AndroidManifest.xml'
    }
  }

  adbOptions {
    installOptions "-g"
  }

  signingConfigs {
    release {
      if (!System.getenv('CI')) {
        storeFile file(ELIFUT_CERT_PATH)
        storePassword ELIFUT_CERT_PASSWORD
        keyAlias "elifut"
        keyPassword ELIFUT_CERT_PASSWORD
      }
    }
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  buildTypes {
    debug {
      multiDexEnabled true
      buildConfigField "String", "API_ENDPOINT", "\"$prodApiEndpoint\""
    }
    release {
      buildConfigField "String", "API_ENDPOINT", "\"$prodApiEndpoint\""
      minifyEnabled true
      multiDexEnabled false
      // Assume that Proguard will strip out a huge bunch of classes and methods.
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      signingConfig signingConfigs.release
    }
  }

  testOptions {
    unitTests.returnDefaultValues = true
    unitTests.includeAndroidResources = true
  }

  dexOptions {
    javaMaxHeapSize "4g"
  }

  packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/MANIFEST.MF'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/services/javax.annotation.processing.Processor'
    exclude 'META-INF/services/com.google.auto.value.extension.AutoValueExtension'
    exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
    exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
    exclude 'LICENSE.txt'
  }
}

dependencies {
  implementation "com.android.support:design:$supportLibVersion"
  implementation "com.android.support:appcompat-v7:$supportLibVersion"
  implementation "com.android.support:cardview-v7:$supportLibVersion"
  implementation "com.android.support:palette-v7:$supportLibVersion"
  implementation "com.android.support:recyclerview-v7:$supportLibVersion"
  implementation "com.google.android.gms:play-services-base:$playServicesVersion"
  implementation "com.google.android.gms:play-services-analytics:$playServicesVersion"
  implementation "com.google.android.gms:play-services-games:$playServicesVersion"
  implementation 'com.squareup.picasso:picasso:2.6.0-SNAPSHOT'
  implementation "io.reactivex:rxjava:$rxJavaVersion"
  implementation "com.jakewharton.rxbinding:rxbinding:$rxBindingVersion"
  implementation 'io.reactivex:rxandroid:1.2.1'
  implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"
  implementation "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"
  implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
  implementation "com.squareup.retrofit2:adapter-rxjava:$retrofitVersion"
  implementation "com.squareup.retrofit2:converter-moshi:$retrofitVersion"
  implementation "com.jakewharton:butterknife:$butterknifeVersion"
  implementation "com.google.dagger:dagger:$daggerVersion"
  implementation "com.squareup.moshi:moshi:$moshiVersion"
  implementation "frankiesardo:icepick:$icepickVersion"
  implementation "com.github.rahatarmanahmed:circularprogressview:$circularProgressViewVersion"
  debugImplementation "com.facebook.stetho:stetho-okhttp3:$stethoVersion"
  debugImplementation "com.facebook.stetho:stetho-js-rhino:$stethoVersion"
  debugImplementation 'com.android.support:multidex:1.0.3'
  debugImplementation "com.airbnb.okreplay:okreplay:$okReplayVersion"
  implementation 'com.timehop.stickyheadersrecyclerview:library:0.4.3'
  implementation "com.google.guava:guava:$guavaVersion"
  implementation 'org.apache.commons:commons-math3:3.6.1'
  implementation 'com.f2prateek.rx.preferences:rx-preferences:1.0.2'
  implementation "com.squareup.sqlbrite:sqlbrite:$sqlbriteVersion"
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
  implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
  implementation "com.gabrielittner.auto.value:auto-value-cursor-annotations:$autoValueCursorVersion"
  implementation("com.crashlytics.sdk.android:crashlytics:$crashlyticsVersion@aar") {
    transitive = true
  }

  releaseImplementation "com.airbnb.okreplay:noop:$okReplayVersion"

  annotationProcessor "frankiesardo:icepick-processor:$icepickVersion"
  compileOnly 'org.glassfish:javax.annotation:10.0-b28'
  compileOnly "com.google.auto.value:auto-value:$autoValueVersion"
  compileOnly "com.ryanharter.auto.value:auto-value-moshi:$autoValueMoshiVersion"

  annotationProcessor "com.google.auto.value:auto-value:$autoValueVersion"
  annotationProcessor "com.squareup:javapoet:$javapoetVersion"
  annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
  annotationProcessor "com.ryanharter.auto.value:auto-value-parcel:$autoValueParcelVersion"
  annotationProcessor "com.ryanharter.auto.value:auto-value-moshi:$autoValueMoshiVersion"
  annotationProcessor "com.gabrielittner.auto.value:auto-value-cursor:$autoValueCursorVersion"
  annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion"
  annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
  annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion"

  testImplementation 'junit:junit:4.12'
  testImplementation 'org.mockito:mockito-core:1.10.19'
  testImplementation 'org.assertj:assertj-core:1.7.1'
  testImplementation "com.google.dagger:dagger:$daggerVersion"
  testImplementation "com.google.guava:guava:$guavaVersion"
  testAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
  testImplementation "com.google.dagger:dagger-compiler:$daggerVersion"
  testImplementation "org.robolectric:shadows-multidex:$robolectricVersion"
  testImplementation("org.robolectric:robolectric:$robolectricVersion") {
    exclude module: 'classworlds'
    exclude module: 'commons-logging'
    exclude module: 'httpclient'
    exclude module: 'maven-artifact'
    exclude module: 'maven-artifact-manager'
    exclude module: 'maven-error-diagnostics'
    exclude module: 'maven-model'
    exclude module: 'maven-project'
    exclude module: 'maven-settings'
    exclude module: 'plexus-container-default'
    exclude module: 'plexus-interpolation'
    exclude module: 'plexus-utils'
    exclude module: 'wagon-file'
    exclude module: 'wagon-http-lightweight'
    exclude module: 'wagon-provider-api'
  }

  androidTestImplementation 'com.google.code.findbugs:jsr305:2.0.1'
  androidTestImplementation 'com.android.support:multidex:1.0.3'
  androidTestImplementation "com.airbnb.okreplay:espresso:$okReplayVersion"
  androidTestImplementation "com.android.support.test.espresso:espresso-intents:$espressoVersion"
  androidTestImplementation "com.android.support.test:runner:$supportTestVersion"
  androidTestImplementation "com.android.support.test:rules:$supportTestVersion"
  androidTestImplementation "com.android.support.test.espresso:espresso-core:$espressoVersion"
  androidTestImplementation 'com.jakewharton.espresso:okhttp3-idling-resource:1.0.0'

}

apply plugin: 'com.google.gms.google-services'
