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

android {
    compileSdkVersion 28
    buildToolsVersion "30.0.3"
    ndkVersion "25.2.9519653"

    lintOptions {
        disable 'ExpiredTargetSdkVersion'
    }

    defaultConfig {
        applicationId "org.satdump.SatDump"
        namespace "org.satdump.SatDump"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 8
        versionName "1.2.2"
    }

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

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    
    packagingOptions {
        jniLibs {
            useLegacyPackaging = true
        }
    }

    kotlinOptions {
        jvmTarget="1.8"
    }

    externalNativeBuild {
        cmake {
            path "../CMakeLists.txt"
        }
    }

    sourceSets {
        main {
            assets.srcDirs += ['assets']
        }
    }
}

task deleteTempAssets (type: Delete) {
    delete 'assets'
}

task copyResources(type: Copy) {
    description = 'Copy resources...'
    from '../../resources'
    into 'assets/resources'
    include('**/*')
}

task copyPipelines(type: Copy) {
    description = 'Copy pipelines...'
    from '../../pipelines'
    into 'assets/pipelines'
    include('**/*')
}

task copyCfg(type: Copy) {
    description = 'Copy config...'
    from '../../satdump_cfg.json'
    into 'assets/'
    include('*')
}

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
}

copyResources.dependsOn deleteTempAssets
copyPipelines.dependsOn deleteTempAssets
copyCfg.dependsOn deleteTempAssets

preBuild.dependsOn copyResources
preBuild.dependsOn copyPipelines
preBuild.dependsOn copyCfg
