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

android {
    namespace "it.airgap.wallet"
    compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 31
    defaultConfig {
        applicationId "it.airgap.wallet"
        minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
        targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 31
        versionCode 1
        versionName "0.0.0"
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildFeatures {
        buildConfig true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }

    flavorDimensions "repository"
    productFlavors {
        playstore {
            dimension "repository"
            isDefault true

            buildConfigField("String", "PRODUCT_FLAVOR", '"playstore"')
        }

        fdroid {
            dimension "repository"

            buildConfigField("String", "PRODUCT_FLAVOR", '"fdroid"')
        }
    }
  lint {
    disable 'MissingDefaultResource'
  }
}

repositories {
    google()
    jcenter()
    flatDir{
        dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
    }
    mavenCentral()
}

dependencies {
    implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
    implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
    implementation 'androidx.webkit:webkit:1.7.0'
    implementation project(':capacitor-android')
    testImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test:core:$androidxTestCoreVersion"
    androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
    implementation project(':capacitor-cordova-android-plugins')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    def coroutinesVersion = "1.6.4"
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")

    def saplingVersion = "0.0.7"
    implementation "com.github.airgap-it:airgap-sapling:$saplingVersion"

    implementation "org.bouncycastle:bcprov-jdk15on:1.70"

    implementation "androidx.javascriptengine:javascriptengine:1.0.0-alpha05"
    implementation 'com.google.guava:listenablefuture:1.0'
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-guava:$coroutinesVersion"
}

apply from: 'capacitor.build.gradle'


configurations.each {
  if (it.name.startsWith("fdroid")) {
    it.exclude group: 'com.google.firebase', module: ''
    it.exclude group: 'com.google.android.gms', module: ''
  }
}

try {
    def servicesJSON = file('google-services.json')
    if (servicesJSON.text) {
        apply plugin: 'com.google.gms.google-services'
    }
} catch(Exception e) {
    logger.warn("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}
