plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'com.google.dagger.hilt.android'
}

android {
    namespace 'net.buzzert.kordophonedroid'
    compileSdk 33

    defaultConfig {
        applicationId "net.buzzert.kordophonedroid"
        minSdk 30
        targetSdk 33
        versionCode 1
        versionName "1.0"

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

    signingConfigs {
        if (project.hasProperty('RELEASE_STORE_FILE')) {
            release {
                storeFile file(RELEASE_STORE_FILE)
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

            if (project.hasProperty('RELEASE_STORE_FILE')) {
                signingConfig signingConfigs.release
            }
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }

    buildFeatures {
        compose true
    }

    composeOptions {
        // Note: this is strictly tied to a kotlin version, but isn't the version of kotlin exactly.
        // See: https://developer.android.com/jetpack/androidx/releases/compose-kotlin
        kotlinCompilerExtensionVersion '1.4.8'
    }

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

    splits {
        abi {
            // Enable building for multiple ABIs
            enable true 

            // Include x86/x86_64 APKs
            include "x86", "x86_64"
            universalApk false 
        }
    }

    buildToolsVersion '33.0.1'
}

kotlin {
    jvmToolchain(8)
}

dependencies {
    implementation "androidx.compose.material3:material3:1.1.1"
    implementation "androidx.core:core-ktx:${kotlin_version}"

    // Kordophone lib
    implementation project(':backend')
    implementation 'androidx.security:security-crypto-ktx:1.1.0-alpha06'

    // Navigation
    def nav_version = "2.6.0"

    // Java language implementation
    implementation "androidx.navigation:navigation-fragment:$nav_version"
    implementation "androidx.navigation:navigation-ui:$nav_version"

    // Kotlin
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

    // Feature module Support
    implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"

    // Testing Navigation
    androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"

    // Jetpack Compose Integration
    implementation "androidx.navigation:navigation-compose:$nav_version"

    // Jetpack Compose
    def compose_version = "1.4.3"
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.foundation:foundation:$compose_version"


    implementation "androidx.activity:activity-compose:$compose_version"

    // Lifecycle
    def lifecycle_version = "2.6.1"
    implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"


    // Hilt (dependency injection)
    implementation "com.google.dagger:hilt-android:${hilt_version}"
    implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
    kapt "com.google.dagger:hilt-compiler:${hilt_version}"

    // Coil (image loading library)
    implementation "io.coil-kt:coil:2.4.0"
    implementation "io.coil-kt:coil-compose:2.4.0"

    // Disk LRU Cache
    implementation "com.jakewharton:disklrucache:2.0.2"

    // Zooming in images
    implementation "net.engawapg.lib:zoomable:$compose_version"

    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
}

// Allow references to generated code
kapt {
    correctErrorTypes true
}
