import org.gradle.internal.os.OperatingSystem;

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    // Each version of the Android Gradle Plugin now has a default version of the build tools
    //buildToolsVersion '29.0.2'

    // don't use Android.mk generated by Android Studio / Gradle
    sourceSets.main.jniLibs.srcDirs = ['src/main/libs']

    defaultConfig {
        applicationId "org.flare.app"
        minSdkVersion 16
        targetSdkVersion 29
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    namespace 'org.flare.app'
}

// call regular ndk-build script from app directory
task ndkBuild(type: Exec) {
    if (OperatingSystem.current().isWindows()) {
        commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath, '-j', Runtime.runtime.availableProcessors()
    } else {
        commandLine 'ndk-build', '-C', file('src/main').absolutePath, '-j', Runtime.runtime.availableProcessors()
    }
}

task ndkClean(type: Exec) {
    if (OperatingSystem.current().isWindows()) {
        commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath, 'clean'
    } else {
        commandLine 'ndk-build', '-C', file('src/main').absolutePath, 'clean'
    }
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

clean.dependsOn 'ndkClean'