/*
 * 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'
//apply plugin: 'codeporter'
plugins {
    id 'com.android.application'
    id('niap.codeporter')
}


def homePath = System.properties['user.home']
def applicationName = 'Tester'
android {
    signingConfigs {
        // TODO :
        // Prepare your own normal.jks and platform.jks as settings and put these into
        // assigned path. It helps to build the application variants automatically.
        // For details see the instructions on the SIGNING.md
        norm{
            storeFile file("../security/normal/normal.jks")
            storePassword "android"
            keyPassword "android"
            keyAlias "normal"
        }
        platform {
            storeFile file('../security/platform/platform.jks')
            storePassword "android"
            keyPassword "android"
            keyAlias "platform"
        }
        debugkeystore {
            storeFile file(homePath+'/.android/debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }

    def publish = project.tasks.create("publishAll")
    testVariants.all { variant->
        if(variant.buildType.name.equals("debug")){
            def task = project.tasks.create("publish${variant.name.capitalize()}Test", Copy)
            mkdir("$rootDir/package")
            variant.outputs.all { item ->
                task.from(item.outputFile)
                //println(item.outputFile)
            }
            task.into("$rootDir/package")
            task.dependsOn variant.assemble
            publish.dependsOn task
        }
    }
    applicationVariants.all { variant ->
        variant.outputs.all {
            def flavor = variant.productFlavors.name[0]
            outputFileName = "${applicationName}-${flavor}-${variant.buildType.name}.apk"
        }
        if(variant.buildType.name.equals("debug")){
            def task = project.tasks.create("publish${variant.name.capitalize()}Apk", Copy)
            mkdir("$rootDir/package")
            variant.outputs.all { item ->
                task.from(item.outputFile)
            }
            task.into("$rootDir/package")
            task.dependsOn variant.assemble
            publish.dependsOn task
        }
    }
    compileSdk 35
    //compileSdkPreview "VanillaIceCream"

    defaultConfig {
        applicationId "com.android.certifications.niap.permissions"
        //targetSdkPreview "VanillaIceCream"
        //minSdkPreview "29"
        minSdkVersion 29
        //noinspection EditedTargetSdkVersion
        targetSdkVersion 35
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            signingConfig null
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            signingConfig null
            debuggable true
        }
    }
    flavorDimensions "settings"
    productFlavors {
        normal {
            dimension "settings"
            signingConfig signingConfigs.norm
        }
        noperm {
            dimension "settings"
            signingConfig signingConfigs.norm
        }
        platform {
            dimension "settings"
            signingConfig signingConfigs.platform
        }
    }
    compileOptions {
        targetCompatibility = "11"
        sourceCompatibility = "11"
    }
    lint {
        abortOnError false
    }
    namespace 'com.android.certifications.niap.permissions'
    buildFeatures {
        aidl true
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.android.material:material:1.12.0'
    implementation 'com.google.android.gms:play-services-location:21.2.0'
    implementation 'com.google.android.gms:play-services-vision:20.1.3'
    implementation 'com.google.android.gms:play-services-base:18.4.0'
    implementation 'com.google.android.material:material:1.12.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation "com.google.guava:guava:32.0.1-jre"
    implementation 'com.google.code.gson:gson:2.10.1'
    implementation 'androidx.work:work-runtime:2.9.0'
    implementation "androidx.credentials:credentials:1.2.2"
    implementation 'androidx.test:runner:1.5.2'
    implementation "androidx.preference:preference:1.2.1"
    implementation "com.github.javaparser:javaparser-core:3.3.0"
    //androidx.text 1.5.0 has compatibility problems
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test:core:1.4.0'
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation 'androidx.test:rules:1.4.0'
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.3.0-alpha04'

}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}