apply plugin: 'com.android.application'

repositories {
    mavenCentral()
    jcenter()
}

task nativeLibsToJar(
    type: Zip,
    description: 'create a jar archive of the native libs') {
    destinationDir file("$buildDir/native-libs")
    baseName 'native-libs'
    extension 'jar'
    from fileTree(dir: 'libs', include: '**/*.so')
    into 'lib/'
}

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

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

dependencies {
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.googlecode.mp4parser:isoparser:1.0.6'
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    compile 'com.google.zxing:core:3.3.0'
    compile 'com.journeyapps:zxing-android-embedded:3.4.0'
    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
}

android {
    compileSdkVersion 25       // should be ...
    buildToolsVersion '25.0.2' // ... in sync unless you know exactly what you're doing

    useLibrary 'org.apache.http.legacy'
    defaultConfig.applicationId = "com.b44t.messenger"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    lintOptions {
        abortOnError false
    }

    signingConfigs {
        debug {
            def debugKeystore = file("config/debug.keystore")
            if (debugKeystore.exists()) {
                storeFile debugKeystore
            }
        }

        release {
            storeFile file("config/release.keystore")
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }

    buildTypes {
        debug {
            debuggable true
            jniDebuggable true
            signingConfig signingConfigs.debug
            applicationIdSuffix ".beta"
        }

        release {
            debuggable false
            jniDebuggable false
            signingConfig signingConfigs.release
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets.main {
        jniLibs.srcDir 'libs'
        jni.srcDirs = [] //disable automatic ndk-build call
    }

    flavorDimensions "none"
    productFlavors {
        /*
        x86 {
            ndk {
                abiFilter "x86"
            }
            versionCode = 2
        }
        arm {
            ndk {
                abiFilter "armeabi"
            }
            versionCode = 0
        }
        armv7 {
            ndk {
                abiFilter "armeabi-v7a"
            }
            versionCode = 1
        }
        */
        fat {
            dimension "none"
            //versionCode = 3
        }
    }

    /*applicationVariants.all { variant ->
        def abiVersion = variant.productFlavors.get(0).versionCode
        variant.mergedFlavor.versionCode = defaultConfig.versionCode * 10 + abiVersion;
    }*/

    defaultConfig {
        minSdkVersion 14     // 14: Android 4.0 Ice Cream Sandwich 2011 (Telegram default), 21: Android 5.0 Lollipop 2014 (provides JobScheduler, recommended for InstantRun)
        targetSdkVersion 25  // 25: Nougat. CAVE: Do NOT target "Andoid O" without checking the background tasks carefully, see https://developer.android.com/preview/behavior-changes.html#back-all . As long as we target "Nougat", everything works as expected even for "Andoid O" or later
                             // in general, we should not change the target without reason; eg. after the switch to Nougat, the camera stops working (see https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en )

        versionName "0.18.2" // do NOT forget to increase defaultConfig.versionCode!
        versionCode 534
    }
}
