plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'org.jetbrains.kotlin.plugin.compose'
    id 'org.jetbrains.kotlin.plugin.parcelize'
}

final def gitHash = providers.exec {
    commandLine('git', 'rev-parse', '--short=7', 'HEAD')
}.standardOutput.asText.get().trim()

kotlin {
    jvmToolchain(11)
}

android {
    namespace 'dev.fabik.bluetoothhid'
    compileSdkVersion 36

    defaultConfig {
        applicationId "dev.fabik.bluetoothhid"
        minSdk 28
        targetSdk 36
        versionCode 53
        versionName "2.1.0-rc.1"

        buildConfigField "String", "GIT_COMMIT_HASH", "\"${gitHash}\""

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary false
        }
    }

    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
        }
    }

    final def isBuildingBundle = gradle.startParameter.taskNames.any { it.toLowerCase().contains("bundle") }

    splits {
        abi {
            // split abi not supported for bundles
            enable !isBuildingBundle

            reset()
            include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"

            universalApk true
        }
    }

    buildFeatures {
        compose true
        buildConfig true
    }

    composeOptions {
        kotlinCompilerExtensionVersion '1.4.2'
    }

    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
            excludes += "DebugProbesKt.bin"
        }
    }

    lint {
        disable "NullSafeMutableLiveData"
    }
}

configurations {
    all*.exclude group: 'androidx.appcompat', module: 'appcompat'
}

dependencies {
    implementation "androidx.javascriptengine:javascriptengine:1.0.0"

    implementation 'androidx.core:core-ktx:1.17.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.9.4'
    implementation 'androidx.activity:activity-compose:1.11.0'

    implementation "androidx.compose.ui:ui:$compose_ui_version"
    implementation "androidx.compose.material:material-icons-extended:$compose_mat_version"
    implementation "androidx.compose.runtime:runtime-livedata:$compose_ui_version"
    implementation 'androidx.compose.material3:material3:1.4.0'

    implementation 'androidx.navigation:navigation-compose:2.9.5'
    implementation 'androidx.datastore:datastore-preferences:1.1.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-view:$camerax_version"
    implementation "androidx.camera:camera-compose:$camerax_version"

    implementation 'io.github.zxing-cpp:android:2.3.0'

    implementation "com.google.accompanist:accompanist-permissions:$accomp_version"

    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.mockito:mockito-core:5.20.0'
    testImplementation 'org.mockito.kotlin:mockito-kotlin:6.1.0'
    testImplementation 'org.robolectric:robolectric:4.14'

    androidTestImplementation 'androidx.test.ext:junit:1.3.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"

    implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
}
