plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "org.openblack.app"
        minSdk 21
        targetSdk 32
        ndkVersion "26.3.11579264"
        versionCode 1
        versionName "0.1.0"
        archivesBaseName = "${applicationId}-${versionName}"

        // To use this configuration, pre-built native libraries must be placed into the respective directories:
        // For debug build variant, place libraries in 'src/main/jniLibs/Debug' and call ./gradlew assembleDebug -PusePrebuiltNativeLibs
        // For release build variant, place libraries in 'src/main/jniLibs/Release' and call ./gradlew assembleRelease -PusePrebuiltNativeLibs
        // In android studio, add -PusePrebuiltNativeLibs to the "Command-line Options" in "Build, Execution, Deployment" / "Compiler".
        if (project.hasProperty("usePrebuiltNativeLibs")) {
            sourceSets {
                debug {
                    jniLibs.srcDirs = ['src/main/jniLibs/debug']
                }
                release {
                    jniLibs.srcDirs = ['src/main/jniLibs/release']
                }
            }
        }
        else {
            externalNativeBuild {
                cmake {
                    cppFlags "-std=c++20"
                    targets "openblack_lib"
                    arguments '-DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake',
                              '-DANDROID_NDK_HOME='+android.ndkDirectory,
                              '-DVCPKG_TARGET_ANDROID=ON',
                              '-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE='+android.ndkDirectory+'/build/cmake/android.toolchain.cmake',
                              '-DANDROID_PLATFORM=android-'+minSdk
                }
            }
        }
    }

    signingConfigs {
        create("release") {
            if (System.getenv("STORE_KEY") != null) {
                storeFile = file(System.getenv("STORE_KEY"))
                storePassword = System.getenv("STORE_PASSWORD")
                keyAlias = System.getenv("STORE_KEY_ALIAS")
                keyPassword = System.getenv("STORE_PASSWORD")
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (System.getenv("STORE_KEY") != null) {
                signingConfig = signingConfigs.getByName("release")
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    if (!project.hasProperty("usePrebuiltNativeLibs")) {
        externalNativeBuild {
            cmake {
                path file('../../CMakeLists.txt')
                version '3.18.1'
            }
        }
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {
    implementation 'androidx.documentfile:documentfile:1.0.1'
}
