/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * 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'
def applicationName = 'Companion'
android {
    //compileSdkPreview "VanillaIceCream"
    //compileSdkPreview "Baklava"
    compileSdk 36
    signingConfigs {
        // TODO :
        // Prepare your own companion.jks and put it into
        // assigned path.
        // For details see the instructions on the SIGNING.md
        // (This key should not be identical to normal.jks file for the Tester app)
        companion {
            storeFile file("../security/companion.jks")
            storePassword "android"
            keyPassword "android"
            keyAlias "companion"
        }
        platform {
            storeFile file('../security/platform.jks')
            storePassword "android"
            keyPassword "android"
            keyAlias "platform"
        }
    }
    defaultConfig {
        applicationId "com.android.certifications.niap.permissions.companion"
        //targetSdkPreview "Baklava"
        targetSdkVersion 36

        minSdk 28
        //minSdkPreview "28"
        versionCode 1
        versionName "1.0"
        signingConfig signingConfigs.platform

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    def publish = project.tasks.create("publishAll")
    applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "${applicationName}-${variant.buildType.name}.apk"
        }
        if(variant.buildType.name.equals("debug")){
            def task = project.tasks.create("publish${variant.name.capitalize()}Apk", Copy)
            variant.outputs.all { item ->
                task.from(item.outputFile)
            }
            task.into("$rootDir/../Tester/package")
            task.dependsOn variant.assemble
            publish.dependsOn task
        }
    }

    buildTypes {
        debug {
            signingConfig null
            debuggable true
            signingConfig signingConfigs.platform
        }
        release {
            signingConfig null
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.companion
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    namespace 'com.android.certifications.niap.permissions.companion'
    buildFeatures {
        aidl true
    }
    lint {
        abortOnError false
    }
}

configurations.implementation {
    exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
    exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk7'
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation 'com.google.android.material:material:1.12.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.android.gms:play-services-location:21.3.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}
