apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.example.android.architecture.blueprints.todoapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
        vectorDrawables{
            useSupportLibrary = true
        }

        // The following argument makes the Android Test Orchestrator run its
        // "pm clear" command after each test invocation. This command ensures
        // that the app's state is completely cleared between tests.
        testInstrumentationRunnerArguments clearPackageData: 'true'
    }

    buildTypes {
        debug {
            minifyEnabled true
            // Uses new built-in shrinker http://tools.android.com/tech-docs/new-build-system/built-in-shrinker
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
        }

        release {
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
        }
    }

    testOptions {
        execution 'ANDROID_TEST_ORCHESTRATOR'
    }

    flavorDimensions "default"

    // If you need to add more flavors, consider using flavor dimensions.
    productFlavors {
        mock {
            dimension "default"
            applicationIdSuffix = ".mock"
        }
        prod {
            dimension "default"
        }
    }

    // Remove mockRelease as it's not needed.
    android.variantFilter { variant ->
        if (variant.buildType.name == 'release'
                && variant.getFlavors().get(0).name == 'mock') {
            variant.setIgnore(true)
        }
    }

    // Always show the result of every unit test, even if it passes.
    testOptions.unitTests.all {
        testLogging {
            events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
        }
    }
}

/*
 Dependency versions are defined in the top level build.gradle file. This helps keeping track of
 all versions in a single place. This improves readability and helps managing project complexity.
 */
dependencies {
    // App's dependencies, including test
    implementation "com.android.support:preference-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:design:$rootProject.supportLibraryVersion"
    implementation "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion"
    implementation "com.android.support.test.espresso:espresso-idling-resource:$rootProject.espressoVersion"
    implementation "com.google.guava:guava:$rootProject.guavaVersion"
    implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
    implementation "com.android.support:preference-v14:$rootProject.supportLibraryVersion"

    implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion"
    implementation "com.android.support:support-vector-drawable:$rootProject.supportLibraryVersion"
    annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
    androidTestUtil 'com.android.support.test:orchestrator:1.0.2'

    // Android Testing Support Library's runner and rules
    androidTestImplementation "com.android.support.test:runner:$rootProject.ext.runnerVersion"
    androidTestImplementation "com.android.support.test:rules:$rootProject.ext.rulesVersion"
    androidTestImplementation "android.arch.persistence.room:testing:$rootProject.roomVersion"

    // Espresso UI Testing
    androidTestImplementation "com.android.support.test.espresso:espresso-core:$rootProject.espressoVersion"
    androidTestImplementation "com.android.support.test.espresso:espresso-contrib:$rootProject.espressoVersion"
    androidTestImplementation "com.android.support.test.espresso:espresso-intents:$rootProject.espressoVersion"
    androidTestImplementation "com.android.support.test.espresso.idling:idling-concurrent:$rootProject.espressoVersion"
    androidTestImplementation "com.android.support.test.espresso:espresso-idling-resource:$rootProject.espressoVersion"
    androidTestImplementation "com.android.support.test.espresso:espresso-web:$rootProject.espressoVersion"
    androidTestImplementation "com.android.support.test.espresso:espresso-accessibility:$rootProject.espressoVersion"

    // Accessibility and UI Automator dependencies
    androidTestImplementation "com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:$rootProject.accessibilityFramework"
    androidTestImplementation "com.android.support.test.uiautomator:uiautomator-v18:$uiautomatorVersion"

    // Squareup dependencies
    androidTestImplementation "com.squareup.okhttp3:okhttp:3.13.1"
    implementation "com.squareup.picasso:picasso:2.5.2"

    // ConditionalWatcher dependency
    androidTestImplementation "com.azimolabs.conditionwatcher:conditionwatcher:0.2"

    // Resolve conflicts between main and test APK:
    androidTestImplementation "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
    androidTestImplementation "com.android.support:support-v4:$rootProject.supportLibraryVersion"
    androidTestImplementation "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
    androidTestImplementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    androidTestImplementation "com.android.support:design:$rootProject.supportLibraryVersion"
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
