apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 34
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 24
        targetSdkVersion 34
        versionCode 1
        versionName "1.0"
    }
    packagingOptions.jniLibs.keepDebugSymbols += "**/libdispatch.so"
    buildTypes {
        release {
            minifyEnabled false
        }
    }
    splits {
        abi {
            reset()
            enable true
            universalApk false
            include "arm64-v8a"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = '17'
    }

    namespace 'com.flowkey.uikit.example' 
}

task buildSwiftArm64(type: Exec) {
    commandLine 'sh', '-c', getSwiftBuildCommand('arm64-v8a')
}

task cleanSwift(type: Exec) {
    commandLine 'sh', '-c', "rm -rf ../../.build"
}

preBuild.dependsOn buildSwiftArm64

clean.dependsOn cleanSwift

def getSwiftBuildCommand(abi) {
    def BUILD_TYPE = "release"
    def buildScript = "../../../../swift-android-toolchain/swiftpm.sh"
    return "ANDROID_ABI=$abi LIBRARY_OUTPUT_DIRECTORY='${projectDir}/src/main/jniLibs/${abi}' $buildScript -c $BUILD_TYPE --package-path ../.."
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    api project(":uikit")
}
