plugins {
    id 'com.android.library'
}

android {
    namespace 'com.termux.x11'
    compileSdk 34

    defaultConfig {
        targetSdk 34
        minSdk 26
        buildConfigField "String", "COMMIT", "\"" + ("git rev-parse HEAD\n".execute().getText().trim() ?: (System.getenv('CURRENT_COMMIT') ?: "NO_COMMIT")) + "\""
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
        externalNativeBuild {
            cmake {
                cppFlags ""
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    if (isWindows()||isMacOS()){
        sourceSets {
            main {
                jniLibs.srcDirs = ['libs']
            }
        }
    }else{
        externalNativeBuild {
            cmake {
                path "src/main/cpp/CMakeLists.txt"
                version "3.22.1"
            }
        }
    }
    splits {
        abi {
            include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
            universalApk true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_9
        targetCompatibility JavaVersion.VERSION_1_9
    }
    packagingOptions {
        jniLibs {
            useLegacyPackaging false
        }
    }
    buildFeatures {
        viewBinding true
    }
    buildFeatures.aidl true
    buildFeatures.buildConfig true
    buildToolsVersion '34.0.0'
    ndkVersion '25.1.8937393'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.preference:preference:1.2.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
    compileOnly project(':shell-loader:stub')
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

    implementation 'com.google.android.material:material:1.4.0'
    implementation 'com.github.luben:zstd-jni:1.5.2-3@aar'
    implementation 'org.tukaani:xz:1.7'
    implementation 'org.apache.commons:commons-compress:1.20'

}

static def isWindows() {
    println(System.properties['os.name']);
    return System.properties['os.name'].contains('windows');
}

static def isMacOS() {
    println(System.properties['os.name']);
    return System.properties['os.name'].contains('Mac OS X');
}
