// Copyright 2020 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.

apply plugin: 'com.android.application'
// Firebase performance plugin, the relevant dependency is specified in the "buildSrc/build-src.gradle"
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
apply plugin: 'copy-google-services'

// Since Test Lab devices are wiped off immediately (for both Security and Privacy reasons) we have
// previously seen issues pertaining to the App not sending data to our backend when the
// instrumentation tests were run on the Test Lab. For now the below configuration of device seem to
// be working fine but in case we see similar issues in the future we should consider following the
// advice in b/168905187#comment6.
firebaseTestLab {
    device 'model=Pixel2,version=28,locale=en,orientation=portrait'
}

android {
    compileSdkVersion project.compileSdkVersion

    namespace "com.google.firebase.testing.fireperf"
    // Specifies the build type that the Android plugin should use to run the instrumentation tests.
    // TL;DR Configure what build types should Firebase Test Lab (FTL) runs your tests on.
    // https://bit.ly/3j1smXH
    //
    // Note: Currently we can only run tests against one build type (see https://stackoverflow.com/a/18064368)
    // and the current Infra setup only supports "release" builds (see https://bityl.co/3DUi and https://bityl.co/3DUl).
    testBuildType = "release"

    lintOptions {
        abortOnError true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // NOTE: This can be different than the package name.
        // https://developer.android.com/studio/build/application-id.html
        applicationId "com.google.firebase.testing.fireperf"

        minSdkVersion project.minSdkVersion
        targetSdkVersion project.targetSdkVersion
        versionCode 3
        versionName "3.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        proguardFiles 'proguard-rules.pro'

        // Enabling multidex support.
        multiDexEnabled true
    }

    buildTypes {
        // This is so we can build the "release" variant for the "dev-app" (and the SDK) without
        // needing to have the app signed.
        release {
            initWith debug
        }
    }
}

dependencies {
    // Firebase Deps
    if (project.hasProperty("fireperfBuildForAutopush")) {
        println("Building with HEAD version ':firebase-perf' of SDK")
        implementation project(":firebase-perf")

    } else {
        println("Building with latest public version ':firebase-perf:$latestReleasedVersion' of SDK")
        implementation "com.google.firebase:firebase-perf:$latestReleasedVersion"
    }

    // Google Deps
    implementation "com.google.android.gms:play-services-tasks:18.0.1"
    implementation "com.google.guava:guava:30.1.1-android"
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation "androidx.recyclerview:recyclerview:1.1.0"
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
    implementation 'androidx.navigation:navigation-fragment:2.3.5'
    implementation 'androidx.navigation:navigation-ui:2.3.5'
    implementation 'com.google.android.material:material:1.4.0'

    // 3rd party Deps
    implementation 'com.squareup.okhttp3:okhttp:4.9.0'

    // Integration Test Deps
    androidTestImplementation 'junit:junit:4.13.1'
    androidTestImplementation libs.androidx.test.junit
    androidTestImplementation libs.androidx.test.core
    androidTestImplementation 'androidx.test:rules:1.3.0'
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    androidTestImplementation "androidx.test.espresso:espresso-contrib:3.3.0"
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    androidTestImplementation libs.truth
}
