apply plugin: 'com.android.application'
<% if (language == 'kotlin') { %>apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'<% } %>
<% if (language == 'java') { %>apply plugin: "me.tatarka.retrolambda"
apply plugin: "com.neenbedankt.android-apt"
apply from: '../config/quality/quality.gradle'<% } %>

android {
    compileSdkVersion <%= androidTargetSdkVersion %>
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId '<%= appPackage %>'
        minSdkVersion <%= androidMinSdkVersion %>
        targetSdkVersion <%= androidTargetSdkVersion %>

        multiDexEnabled true

        versionCode 1
        versionName "0.0.1"

        testInstrumentationRunner '<%= appPackage %>.MockTestRunner'

    }

    signingConfigs {
        app {
            storeFile file('<%= appPackage %>.keystore')
            storePassword 'android'
            keyAlias 'android'
            keyPassword 'android'
        }
    }

    buildTypes {

        applicationVariants.all { variant ->
            if (variant.getBuildType().isMinifyEnabled()) {
                variant.assemble.doLast {
                    copy {
                        from variant.mappingFile
                        into "${rootDir}/proguardTools"
                        rename { String fileName ->
                            "mapping-${variant.name}.txt"
                        }
                    }
                }
            }
        }

        all {
            buildConfigField 'String', 'API_ENDPOINT_LOCAL', "\"http://example.com\""
            buildConfigField 'String', 'API_ENDPOINT_INTERNAL', "\"http://example.com\""
            buildConfigField 'String', 'API_ENDPOINT_STAGING', "\"http://example.com\""
            buildConfigField 'String', 'API_ENDPOINT_PRODUCTION', "\"http://example.com\""
            buildConfigField 'String', 'CLIENT_ID', "\"CLIENT_ID\""
            buildConfigField 'String', 'CLIENT_SECRET', "\"CLIENT_SECRET\""
        }
        debug {
          def host = InetAddress.getLocalHost().getCanonicalHostName()
          buildConfigField "String", "LOCAL_IP", '\"' + host + '\"'
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            apply plugin: "signing"

            shrinkResources true
            minifyEnabled true

            signingConfig signingConfigs.app

        }
    }

    <% if (language == 'kotlin') { %>sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }<% } %>

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/notice'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/license'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
        pickFirst 'META-INF/maven/com.google.guava/guava/pom.xml'
        exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
        pickFirst 'META-INF/maven/com.google.guava/guava/pom.properties'

        exclude 'META-INF/maven/com.google.dagger/dagger/pom.properties'
        pickFirst 'META-INF/maven/com.google.dagger/dagger/pom.properties'

        exclude 'META-INF/maven/com.google.dagger/dagger/pom.xml'
        pickFirst 'META-INF/maven/com.google.dagger/dagger/pom.xml'

        exclude 'META-INF/license'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/services/org.robolectric.internal.ShadowProvider'
        pickFirst 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'assets/oracle_mobile_cloud_internal_config.xml'
        exclude 'META-INF/rxjava.properties'
    }

    dexOptions {
        preDexLibraries true
        javaMaxHeapSize "4g"
    }

    productFlavors {
        internal {
            applicationId '<%= appPackage %>.internal'
        }
        production {
            applicationId '<%= appPackage %>'
        }
    }
    <% if (language == 'java') { %>
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    <% } %>

    sourceSets {
        // Functional tests live in src/functionalTests.
        androidTest.java.srcDir 'src/functionalTest/java'
    }

    lintOptions {
        disable "InvalidPackage", 'TypographyFractions', 'TypographyQuotes', 'TrustAllX509TrustManager'
    }

    // Always show the result of every unit test, even if it passes.
    testOptions {
        unitTests.returnDefaultValues = true
    }

    testOptions.unitTests.all {
        testLogging {
            events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
        }

    }

}
<% if (language == 'kotlin') { %>
kapt {
    generateStubs = true
}<% } %>
<% if (language == 'java') { %>
apt {
    arguments {
    }
}
retrolambda {
    jvmArgs "-noverify"
}
<% } %>

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    // android-hipster-needle-gradle-dependency

}

<% if (language == 'kotlin') { %>buildscript {

    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        // android-hipster-needle-gradle-parent-dependency
    }
}<% } %>

configurations.compile.dependencies.each { compileDependency ->
    println "Excluding compile dependency: ${compileDependency.getName()}"
    configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
        configurations.androidTestCompile.exclude module: "${compileDependency.getName()}"
    }
}
