buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-rc2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

// Define versions in a single place
ext {
    // Sdk and tools
    minSdkVersion = 10
    targetSdkVersion = 25
    compileSdkVersion = 25
    buildToolsVersion = '26.0.2'

    // App dependencies
    supportLibraryVersion = '25.3.1'
    guavaVersion = '18.0'
    junitVersion = '4.12'
    mockitoVersion = '1.10.19'
    powerMockito = '1.6.2'
    hamcrestVersion = '1.3'
    runnerVersion = '0.5'
    rulesVersion = '0.5'
    espressoVersion = '2.2.2'
}

/*
 * Workaround for https://code.google.com/p/android/issues/detail?id=182715
 *
 * The Android Gradle plugin is creating DataBindingExportBuildInfoTasks for the instrumentation
 * APK that generates from the app APKs layouts. This creates duplicate classes in the app and
 * instrumentation APK which leads to
 *      java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
 * on older devices.
 *
 * The workaround is to get the DataBindingExportBuildInfoTasks tasks for the instrumentation APK
 * and delete the files right after it creates them.
 */
subprojects {
    tasks.withType(com.android.build.gradle.internal.tasks.databinding.DataBindingExportBuildInfoTask) { task ->
        if (task.name.endsWith("AndroidTest")) {
            task.finalizedBy(tasks.create("${task.name}Workaround") << {
                task.output.deleteDir()
            })
        }
    }
}
