import com.android.builder.model.ProductFlavor
import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 21

        versionName "3.1.2"
        versionCode = 56
    }

    productFlavors {
        root {
            applicationId "com.limelight.root"
        }

        nonRoot {
            applicationId "com.limelight"
        }
    }

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

    sourceSets.main.jni.srcDirs = []

    //noinspection GroovyAssignabilityCheck,GroovyAssignabilityCheck
    task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
        Properties properties = new Properties()
        properties.load(project.rootProject.file('local.properties').newDataInputStream())
        def ndkDir = properties.getProperty('ndk.dir')

        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine "$ndkDir\\ndk-build.cmd",
                    'NDK_PROJECT_PATH=build/intermediates/ndk',
                    'NDK_LIBS_OUT=src/main/jniLibs',
                    'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
                    'NDK_APPLICATION_MK=src/main/jni/Application.mk'
        }
        else {
            commandLine "$ndkDir/ndk-build",
                    'NDK_PROJECT_PATH=build/intermediates/ndk',
                    'NDK_LIBS_OUT=src/main/jniLibs',
                    'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
                    'NDK_APPLICATION_MK=src/main/jni/Application.mk'
        }
    }

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

dependencies {
    compile group: 'org.jcodec', name: 'jcodec', version: '0.1.9'

    compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.51'
    compile group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: '1.51'

    compile group: 'com.squareup.okhttp', name: 'okhttp', version:'2.2.0'
    compile group: 'com.squareup.okio', name:'okio', version:'1.2.0'

    compile files('libs/jmdns-fixed.jar')
    compile files('libs/limelight-common.jar')
    compile files('libs/tinyrtsp.jar')
}
