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

android {
    lintOptions {
        abortOnError true
        checkAllWarnings true
        showAll true
        warningsAsErrors true
        checkTestSources true
        textOutput 'stdout'
        htmlReport false
        xmlReport true
        xmlOutput file("${rootProject.buildDir}/reports/lint-results.xml")
        // UnpackedNativeCode can break stack unwinding - see b/193408481
        // NewerVersionAvailable and GradleDependency need to be taken care of
        // by a roller rather than as part of CI.
        // The others are irrelevant for a test application.
        disable 'UnpackedNativeCode','MissingApplicationIcon','GoogleAppIndexingApiWarning','GoogleAppIndexingWarning','GradleDependency','NewerVersionAvailable','Registered'
    }
    buildToolsVersion = '33.0.0'
    compileSdkVersion 33
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    defaultConfig {
        applicationId 'dev.flutter.scenarios'
        minSdkVersion 18
        targetSdkVersion 33
        versionCode 1
        versionName '1.0'
        testInstrumentationRunner 'dev.flutter.TestRunner'
        testInstrumentationRunnerArgument 'listener', 'leakcanary.FailTestOnLeakRunListener'
        testInstrumentationRunnerArguments clearPackageData: 'true'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets.main {
        assets.srcDirs += "${project.buildDir}/assets"
        if (project.hasProperty('libapp')) {
            jni.srcDirs = []
            jniLibs.srcDirs = [project.property('libapp')]
        }
    }
}

dependencies {
    // Please *don't* add embedding dependencies to this file.
    // The embedding dependencies are configured in tools/androidx/files.json.
    // Only add test dependencies.

    if (project.hasProperty('flutter_jar')) {
        implementation files(project.property('flutter_jar'))
    }
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'com.google.guava:guava:30.1-android'

    def leakcanary_version = '2.7'
    androidTestImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
    androidTestImplementation "com.squareup.leakcanary:leakcanary-android-instrumentation:$leakcanary_version"
}

// Configure the embedding dependencies.
apply from: new File(rootDir, '../../../tools/androidx/configure.gradle').absolutePath;
configureDependencies(new File(rootDir, '../../..')) { dependency ->
    dependencies {
        implementation "$dependency"
    }
}

tasks.register('generateLockfiles') {
    rootProject.subprojects.each { subproject ->
        def gradle = "${rootProject.projectDir}/../../../../third_party/gradle/bin/gradle"
        rootProject.exec {
            workingDir rootProject.projectDir
            executable gradle
            args ":${subproject.name}:dependencies", "--write-locks"
        }
    }
}

// Override the kotlin language/api version to avoid warnings from
// usages in leakcanaary.
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

    kotlinOptions {
        jvmTarget = '1.8'
        apiVersion = '1.4'
        languageVersion = '1.4'
    }
}
