apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
apply plugin: 'com.mikepenz.aboutlibraries.plugin'


android {
    compileSdk 34
    defaultConfig {
        applicationId "com.elishaazaria.sayboard"
        minSdkVersion 23
        targetSdkVersion 34
        versionCode 402010
        versionName "v4.2.1"
        ndkVersion "r25c"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    splits {
        abi {
            enable true
            reset()
            include "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
            universalApk true
        }
    }

    android.applicationVariants.configureEach { variant ->
        variant.outputs.configureEach { output ->
//            output.outputFileName = "${variant.getFlavorName()}-${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}-${output.getFilter(com.android.build.OutputFile.ABI)}.apk"
            var abi_name = output.getFilter(output.ABI) ? output.getFilter(output.ABI) : "Universal"
            output.outputFileName = "Sayboard_${abi_name}.apk"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.5.3"
    }

    namespace 'com.elishaazaria.sayboard'

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

    lint {
        lintConfig = file("app/lint.xml")
    }
}

//ext.abiCodes = ['armeabi-v7a':1, x86:2, x86_64:3]
ext.abiCodes = ["armeabi-v7a": 1, "arm64-v8a": 2, "x86": 3, "x86_64": 4]

// For each APK output variant, override versionCode with a combination of
// ext.abiCodes * 1000 + variant.versionCode. In this example, variant.versionCode
// is equal to defaultConfig.versionCode. If you configure product flavors that
// define their own versionCode, variant.versionCode uses that value instead.
android.applicationVariants.configureEach { variant ->

    // Assigns a different version code for each output APK
    // other than the universal APK.
    variant.outputs.each { output ->

        // Stores the value of ext.abiCodes that is associated with the ABI for this variant.
        def variantVersionCode =
                // Determines the ABI for this variant and returns the mapped value.
                project.ext.abiCodes.get(output.getFilter(output.ABI))

        // Because abiCodes.get() returns null for ABIs that are not mapped by ext.abiCodes,
        // the following code doesn't override the version code for universal APKs.
        // However, because you want universal APKs to have the lowest version code,
        // this outcome is desirable.
        if (variantVersionCode != null) {

            // Assigns the new version code to versionCodeOverride, which changes the
            // version code for only the output APK, not for the variant itself. Skipping
            // this step causes Gradle to use the value of variant.versionCode for the APK.
            output.versionCodeOverride =
                    variant.versionCode + variantVersionCode
        }
    }
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.24.4"
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.52.0'
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java { option 'lite' }
            }
            task.plugins {
                grpc { option 'lite' }
            }
        }
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'net.java.dev.jna:jna:5.13.0@aar'
    implementation 'com.alphacephei:vosk-android:0.3.32'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.android.material:material:1.11.0'


    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.7.0'
//    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
//    implementation 'androidx.lifecycle:lifecycle-extensions:2.6.2'
//    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
//    implementation 'androidx.navigation:navigation-fragment:2.7.4'
//    implementation 'androidx.navigation:navigation-ui:2.7.4'
//    implementation 'androidx.preference:preference:1.2.1'

    implementation 'org.greenrobot:eventbus:3.3.1'
    implementation 'dev.gustavoavila:java-android-websocket-client:2.0.1'
    implementation 'io.grpc:grpc-okhttp:1.52.0'
    implementation 'io.grpc:grpc-protobuf-lite:1.52.0'
    implementation 'io.grpc:grpc-stub:1.52.0'
    compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+


    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.0'
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0"

    implementation 'dev.patrickgold.jetpref:jetpref-datastore-model:0.1.0-beta14'
    implementation 'dev.patrickgold.jetpref:jetpref-datastore-ui:0.1.0-beta14'
    implementation 'dev.patrickgold.jetpref:jetpref-material-ui:0.1.0-beta14'

    implementation "org.burnoutcrew.composereorderable:reorderable:0.9.6"

    def composeBom = platform('androidx.compose:compose-bom:2023.10.00')
    implementation composeBom
    androidTestImplementation composeBom

    // Choose one of the following:
    // Material Design 3
//    implementation 'androidx.compose.material3:material3'
    // or Material Design 2
    implementation 'androidx.compose.material:material'
    // or skip Material Design and build directly on top of foundational components
//    implementation 'androidx.compose.foundation:foundation'
    // or only import the main APIs for the underlying toolkit systems,
    // such as input and measurement/layout
//    implementation 'androidx.compose.ui:ui'

    // Android Studio Preview support
    implementation 'androidx.compose.ui:ui-tooling-preview'
    debugImplementation 'androidx.compose.ui:ui-tooling'

    // UI Tests
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'

    // Optional - Included automatically by material, only add when you need
    // the icons but not the material library (e.g. when using Material3 or a
    // custom design system based on Foundation)
//    implementation 'androidx.compose.material:material-icons-core'
    // Optional - Add full set of material icons
    implementation 'androidx.compose.material:material-icons-extended'
    // Optional - Add window size utils
    implementation 'androidx.compose.material3:material3-window-size-class'

    // Optional - Integration with activities
    implementation 'androidx.activity:activity-compose:1.8.2'
    // Optional - Integration with ViewModels
//    implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2'
    // Optional - Integration with LiveData
    implementation 'androidx.compose.runtime:runtime-livedata'
    // Optional - Integration with RxJava
//    implementation 'androidx.compose.runtime:runtime-rxjava2'

    implementation "com.mikepenz:aboutlibraries-compose:11.1.4"
}
