// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

buildscript {
  repositories {
    google()
    mavenCentral()
  }

  dependencies {
    classpath "com.android.tools.build:gradle:8.6.1"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21"
    classpath "com.google.gms:google-services:4.4.3"
    classpath "com.google.firebase:firebase-crashlytics-gradle:3.0.4"
  }
}

apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"

android {
  compileSdkVersion 34
  namespace = "com.google.firebase.testing"
  defaultConfig {
    minSdkVersion 23
    multiDexEnabled true
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    versionName "1.0.0"
  }

  buildTypes {
    release {
      minifyEnabled true
      shrinkResources true
      signingConfig signingConfigs.debug
      proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "smoke-test-rules.pro"
      testProguardFiles "infrastructure-rules.pro"
    }
  }

  compileOptions {
    coreLibraryDesugaringEnabled true
    sourceCompatibility 1.8
    targetCompatibility 1.8
  }

  if (project.hasProperty("testBuildType")) {
    testBuildType project.getProperty("testBuildType")
  }
}

apply from: "configure.gradle"

dependencies {
  implementation libs.androidx.test.core
  // Common utilities (application side)
  implementation "androidx.test:rules:1.5.0"
  implementation "androidx.test:runner:1.6.2"
  // Firebase
  implementation "com.google.firebase:firebase-analytics"
  implementation "com.google.firebase:firebase-annotations"
  implementation "com.google.firebase:firebase-appdistribution:16.0.0-beta15"
  implementation "com.google.firebase:firebase-appdistribution-api:16.0.0-beta15"
  implementation "com.google.firebase:firebase-auth"
  implementation "com.google.firebase:firebase-common"
  implementation "com.google.firebase:firebase-config"
  implementation "com.google.firebase:firebase-crashlytics:19.4.4"
  implementation "com.google.firebase:firebase-database"
  implementation "com.google.firebase:firebase-firestore"
  implementation "com.google.firebase:firebase-functions"
  // TODO(yifany): remove after the issue is fixed
  // https://github.com/firebase/firebase-android-sdk/issues/4206
  implementation "com.google.firebase:firebase-iid"
  implementation "com.google.firebase:firebase-inappmessaging"
  implementation "com.google.firebase:firebase-messaging"
  implementation "com.google.firebase:firebase-ml-modeldownloader:25.0.1"
  implementation "com.google.firebase:firebase-perf"
  implementation "com.google.firebase:firebase-storage"
  implementation "com.google.truth:truth:1.4.4"
  implementation libs.junit

  // Common utilities (instrumentation side)
  androidTestImplementation "androidx.test:runner:1.6.2"
  androidTestImplementation libs.junit

  // Desugaring library
  coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
}

clean.doLast {
  def paths = Files.newDirectoryStream(Paths.get("."), "build-*")

  for (Path path : paths) {
    project.delete "$path/"
  }
}

apply plugin: "com.google.gms.google-services"
apply plugin: "com.google.firebase.crashlytics"
