apply plugin: 'com.android.application'

def getGitHash = { ->
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-parse', '--short', 'HEAD'
        standardOutput = stdout
    }
    return stdout.toString().trim()
}

def ciArg = '-DCI=OFF'
if (project.hasProperty('ciArg')) {
    ciArg = project.property('ciArg').toString()
}

android {
    compileSdk 34
    namespace 'com.github.eka2l1'

    defaultConfig {
        applicationId "com.github.eka2l1"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode 12
        versionName "0.1.0"
        ndkVersion = '25.1.8937393'
        buildConfigField "String", "GIT_HASH", "\"${getGitHash()}\""
        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a"
        }

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                arguments "-DEKA2L1_BUILD_TOOLS=OFF", "-DEKA2L1_BUILD_TESTS=OFF",
                        "-DEKA2L1_BUILD_VULKAN_BACKEND=OFF", ciArg
                cppFlags "-std=c++20"
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            externalNativeBuild {
                cmake {
                    arguments "-DCMAKE_BUILD_TYPE=Release"
                }
            }
        }
        debug {
            ndk {
                abiFilters "x86_64"
            }
            externalNativeBuild {
                cmake {
                    arguments "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
                }
            }
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    externalNativeBuild {
        cmake {
            path "../../../../CMakeLists.txt"
            version "3.22.1"
        }
    }
    buildFeatures {
        viewBinding true
        buildConfig true
    }
    lint {
        abortOnError false
        disable 'MissingTranslation'
    }
}

dependencies {
    def camerax_version = "1.3.0-beta02"

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.documentfile:documentfile:1.0.1'
    implementation 'androidx.preference:preference:1.2.1'
    implementation 'com.google.android.material:material:1.11.0'
    implementation 'com.github.yukuku:ambilwarna:2.0.1'
    implementation 'com.google.code.gson:gson:2.10'
    implementation 'com.github.nikita36078:filepicker:4.3.0'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
    implementation 'org.yaml:snakeyaml:1.27:android'
    implementation 'com.github.skydoves:expandablelayout:1.0.7'
    implementation "androidx.camera:camera-core:${camerax_version}"
    implementation "androidx.camera:camera-camera2:${camerax_version}"
    implementation "androidx.camera:camera-lifecycle:${camerax_version}"
    implementation "androidx.camera:camera-video:${camerax_version}"
    implementation "androidx.camera:camera-view:${camerax_version}"
    implementation "androidx.camera:camera-extensions:${camerax_version}"
    implementation "androidx.camera:camera-mlkit-vision:${camerax_version}"
    implementation "com.google.mlkit:barcode-scanning:17.2.0"
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation "androidx.test:runner:1.5.2"
    androidTestImplementation "androidx.test:rules:1.5.0"
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
