apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    useLibrary 'org.apache.http.legacy'

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    defaultConfig {
        applicationId "com.duosecurity.x_ray"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 3
        versionName "2.1"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets.main {
        jni.srcDirs = [] // This prevents the auto generation of Android.mk
        // This tells gradle to include the objects in libs/ which were generated by running our
        // Android.mk basically by shelling out
        jniLibs.srcDir 'src/main/libs'
    }
}

repositories {
    maven { url "https://jitpack.io" }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'org.apache.commons:commons-compress:1.5'
    compile 'commons-io:commons-io:2.4'
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile('com.afollestad.material-dialogs:core:0.8.5.9') {
        transitive = true
    }
    compile 'com.madgag:sc-light-jdk15on:1.47.0.3'
    compile 'com.madgag:scpkix-jdk15on:1.47.0.3'
    compile 'com.madgag:scprov-jdk15on:1.47.0.3'
    compile 'org.thoughtcrime.ssl.pinning:AndroidPinning:1.0.0'
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')

task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
    commandLine "$ndkDir/ndk-build",
            '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
            '-j', Runtime.runtime.availableProcessors()
}

task cleanNative(type: Exec, description: 'Clean JNI object files') {
    commandLine "$ndkDir/ndk-build",
            '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
            'clean'
}

clean.dependsOn 'cleanNative'


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