plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId 'com.alexbatalov.fallout2ce'
        minSdk 21
        targetSdk 32
        versionCode 2
        versionName '1.1.0'
        externalNativeBuild {
            cmake {
                arguments '-DANDROID_STL=c++_static'
                abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'

                // TODO: Remove once format issues are resolved.
                cppFlags '-Wno-format-security'

                // Specify target library explicitly as there is a shared zlib,
                // that we don't need to be linked in.
                targets 'fallout2-ce'
            }
        }
    }

    signingConfigs {
        // Override default debug signing config to make sure every CI runner
        // uses the same key for painless updates.
        def debugKeystorePropertiesFile = rootProject.file('debug-keystore.properties')
        if (debugKeystorePropertiesFile.exists()) {
            def debugKeystoreProperties = new Properties()
            debugKeystoreProperties.load(new FileInputStream(debugKeystorePropertiesFile))

            debug {
                storeFile rootProject.file(debugKeystoreProperties.getProperty('storeFile'))
                storePassword debugKeystoreProperties.getProperty('storePassword')
                keyAlias debugKeystoreProperties.getProperty('keyAlias')
                keyPassword debugKeystoreProperties.getProperty('keyPassword')
            }
        }

        def releaseKeystoreProperties = new Properties()
        def releaseKeystorePropertiesFile = rootProject.file('release-keystore.properties')
        if (releaseKeystorePropertiesFile.exists()) {
            releaseKeystoreProperties.load(new FileInputStream(releaseKeystorePropertiesFile))

            release {
                storeFile rootProject.file(releaseKeystoreProperties.getProperty('storeFile'))
                storePassword releaseKeystoreProperties.getProperty('storePassword')
                keyAlias releaseKeystoreProperties.getProperty('keyAlias')
                keyPassword releaseKeystoreProperties.getProperty('keyPassword')
            }
        }
    }

    buildTypes {
        debug {
            // Prevents signing keys clashes between debug and release versions
            // for painless development.
            applicationIdSuffix '.debug'
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

            // Release signing config is optional and might not be present in CI
            // builds, hence `findByName`.
            signingConfig signingConfigs.findByName('release')
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    applicationVariants.all { variant ->
        tasks["merge${variant.name.capitalize()}Assets"]
            .dependsOn("externalNativeBuild${variant.name.capitalize()}")
    }

    if (!project.hasProperty('EXCLUDE_NATIVE_LIBS')) {
        sourceSets.main {
            jniLibs.srcDir 'libs'
        }
        externalNativeBuild {
            cmake {
                path '../../../CMakeLists.txt'
            }
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.documentfile:documentfile:1.0.1'
}
