buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.5'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2'
    }

}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

android {
    compileSdkVersion 30

    defaultConfig {
        applicationId "com.spicymango.fanfictionreader"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 99
        versionName "1.63"
    }
    lintOptions {
        abortOnError true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    signingConfigs {
        release
    }
    buildTypes {
        // see https://stackoverflow.com/a/40592469
        def addConstantTo = {target, constantName, constantValue ->
            target.manifestPlaceholders += [ (constantName):constantValue]
            target.buildConfigField "String", "${constantName}", "\"${constantValue}\""
        }
        debug{
            applicationIdSuffix ".debug"
            // buildType-specific provider authority
            // 1. manifestPlaceholders is used by AndroidManifest.xml
            // 2. buildConfigField is used by static constant in StoryProvider.java
            // Note: owner refers to current script block
            addConstantTo(owner, "provider_authority", "com.spicymango.fanfictionreader.debug.provider")
            minifyEnabled true
            ext.enableCrashlytics = false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project-debug.pro'
        }
        release {
            addConstantTo(owner, "provider_authority", "com.spicymango.fanfictionreader.provider")
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.pro'
            signingConfig signingConfigs.release
        }
    }
    packagingOptions {
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE.txt'
    }
}

dependencies {
    implementation project(':kolavar')
    implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
    implementation 'io.reactivex.rxjava3:rxjava:3.0.11'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation "androidx.fragment:fragment:1.3.3"
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'org.jsoup:jsoup:1.11.3'
    implementation 'org.apache.commons:commons-collections4:4.2'
    implementation 'org.apache.commons:commons-lang3:3.8.1'
    implementation 'com.google.firebase:firebase-crashlytics:17.4.1'
    implementation 'com.google.firebase:firebase-analytics:18.0.3'
}

// If the signing configurations are defined in the local gradle.properties, add them to the script
if (project.hasProperty('key.alias')) {
    android.signingConfigs.release.keyAlias = project.property('key.alias')
    android.signingConfigs.release.keyPassword = project.property('key.alias.password')
    android.signingConfigs.release.storeFile = file(project.property('key.store'))
    android.signingConfigs.release.storePassword = project.property('key.store.password')
} else {
    android.buildTypes.release.signingConfig = null
}
