apply plugin: 'com.android.application'

/*
 * 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
 *
 *      https://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.
 */

// Fetch build number from command line arguments (for CI)
ext.build_number = project.hasProperty('BUILD_NUMBER') ? project.getProperty('BUILD_NUMBER') : "1"
ext.build_label = project.hasProperty('BUILD_LABEL') ? project.getProperty('BUILD_LABEL') : "SNAPSHOT"
ext.logsource_id = project.hasProperty('LOGSOURCE_ID') ? project.getProperty('LOGSOURCE_ID') : ""
ext.release_logging = project.hasProperty('RELEASE_LOGGING') && project.getProperty('RELEASE_LOGGING') == "true"

apply from: 'enexpress.gradle'
apply from: 'robolectric_download.gradle'
apply plugin: 'com.google.protobuf'
apply plugin: 'com.mikepenz.aboutlibraries.plugin'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'com.google.gms.google-services'

// Disable unwanted tasks (if any) - see enexpress.gradle
project.tasks.all { task -> 
    if (project.excludedTasks.contains(task.name)) {
        println "Disabling task " + task.name
        task.enabled = false
    }
}

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    ndkVersion rootProject.ext.ndkVersion

    defaultConfig {
        applicationId 'com.google.android.apps.exposurenotification'

        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion

        versionCode build_number.toInteger()
        versionName build_label

        // The value of 'appLinkHost' is placeholder. It is to be replaced with 'appLinkHost' field
        // in the config.
        manifestPlaceholders = [appLinkHost: "applink.host"]

        // This is currently unused, but necessary if we add instrumented tests in the future
        testInstrumentationRunner "com.google.android.apps.exposurenotification.CustomTestRunner"

        vectorDrawables.useSupportLibrary true

        javaCompileOptions {
            annotationProcessorOptions {
                arguments += ["room.schemaLocation":
                                      "$projectDir/schemas".toString()]
            }
        }

        ndk {
            debugSymbolLevel = 'FULL'
        }

        buildConfigField("String", "LOGSOURCE_ID", "\"${logsource_id}\"")
        buildConfigField("boolean", "RELEASE_LOGGING", release_logging.toString())

        if (project.hasProperty('LOCALE_CONFIG')) {
            resConfigs project.getProperty('LOCALE_CONFIG').split(",")
        }
    }

    buildTypes {
        debug {
            pseudoLocalesEnabled true
            versionNameSuffix ".debug"
            minifyEnabled false
            debuggable true
            testCoverageEnabled true
        }

        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    buildFeatures {
        viewBinding true
    }

    sourceSets {
        debug {
            proto {
                srcDirs 'src/main/java/com/google/android/apps/exposurenotification/proto'
            }
            assets {
                srcDirs += files("$projectDir/schemas".toString())
            }
        }
        release {
            proto {
                srcDir 'src/main/java/com/google/android/apps/exposurenotification/proto'
            }
        }
        androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
            returnDefaultValues = true
        }
        unitTests.all {
            maxHeapSize = "2g"
            maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
            forkEvery = 100
            testLogging {
                events "passed", "skipped", "failed", "standardOut", "standardError"
            }
        }
    }

    lintOptions {
        abortOnError false
    }
    buildToolsVersion rootProject.ext.buildToolsVersion
}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.11.4'
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    option "lite"
                }
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    implementation project(':privateanalytics')

    annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
    annotationProcessor 'androidx.room:room-compiler:2.2.5'
    annotationProcessor 'com.google.auto.value:auto-value:1.7.3'
    annotationProcessor 'com.google.dagger:hilt-android-compiler:2.38.1'

    debugImplementation ("androidx.fragment:fragment-testing:1.3.6") {
        exclude group: "androidx.test", module : "core"
    }

    implementation 'androidx.appcompat:appcompat:1.4.0-alpha03'
    implementation "androidx.biometric:biometric:1.1.0"
    implementation "androidx.cardview:cardview:1.0.0"
    implementation 'androidx.concurrent:concurrent-futures:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
    implementation 'androidx.fragment:fragment:1.3.6'
    implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
    implementation 'androidx.hilt:hilt-work:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-process:2.3.0'
    implementation 'androidx.navigation:navigation-fragment:2.3.0'
    implementation 'androidx.room:room-guava:2.2.5'
    implementation 'androidx.room:room-runtime:2.2.5'
    implementation 'androidx.slice:slice-builders:1.0.0'
    implementation ("androidx.work:work-runtime:2.7.0-rc01") {
        transitive = true
    }
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.google.android.gms:play-services-base:17.4.0'
    implementation 'com.google.android.gms:play-services-basement:17.4.0'
    implementation 'com.google.android.gms:play-services-tasks:17.2.0'
    implementation 'com.google.android.material:material:1.5.0-beta01'
    implementation 'com.google.android.play:core:1.10.2'
    implementation 'com.google.auto.value:auto-value-annotations:1.7.3'
    implementation 'com.google.dagger:hilt-android:2.38.1'
    implementation 'com.google.firebase:firebase-firestore:21.6.0'
    implementation 'com.google.firebase:firebase-datatransport:17.0.8'
    implementation 'com.google.guava:guava:29.0-android'
    implementation 'com.google.protobuf:protobuf-javalite:3.11.1'
    implementation 'com.jakewharton.threetenabp:threetenabp:1.2.4'
    implementation 'commons-io:commons-io:2.6'
    implementation 'org.apache.httpcomponents:httpclient:4.5.12'
    implementation "com.mikepenz:aboutlibraries:8.9.4"
    implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.33'

    // Debug-only libraries
    debugImplementation 'com.google.zxing:core:3.3.0'
    debugImplementation('com.journeyapps:zxing-android-embedded:4.1.0') {
        transitive = false
    }

    // JVM test dependencies
    testImplementation 'org.mockito:mockito-core:3.12.4'
    testImplementation 'org.mockito:mockito-inline:3.12.4'
    //noinspection FragmentGradleConfiguration
    testImplementation 'androidx.lifecycle:lifecycle-runtime-testing:2.3.0'
    testImplementation 'androidx.room:room-testing:2.2.5'
    testImplementation 'androidx.test.ext:junit:1.1.4-alpha01'
    testImplementation 'androidx.test:core:1.4.1-alpha01'
    testImplementation "androidx.work:work-testing:2.7.0-rc01"
    testImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    testImplementation 'androidx.test:runner:1.4.0'
    testImplementation 'com.google.guava:guava-testlib:29.0-jre'
    testImplementation 'com.google.dagger:hilt-android-testing:2.38.1'
    testImplementation 'com.google.truth:truth:1.0.1'
    testImplementation 'commons-io:commons-io:2.6'
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.robolectric:robolectric:4.8.1'
    testImplementation 'androidx.arch.core:core-testing:2.1.0'
    testImplementation ('org.threeten:threetenbp:1.2.4'){
        exclude group:'com.jakewharton.threetenabp', module:'threetenabp'
    }
    testAnnotationProcessor 'com.google.dagger:hilt-android-compiler:2.38.1'

    // Instrumented test dependencies
    androidTestImplementation 'androidx.test.ext:junit:1.1.4-alpha01'
    androidTestImplementation 'androidx.test:core:1.4.1-alpha01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'com.google.dagger:hilt-android-testing:2.38.1'
    androidTestAnnotationProcessor 'com.google.dagger:hilt-android-compiler:2.38.1'
}

aboutLibraries {
    configPath = "app/aboutlibraries"
}

configurations {
    all {
        exclude module: 'httpclient'
    }
}
