buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion '20'
    useOldManifestMerger true

    defaultConfig {
        versionCode 16
        versionName '0.8'
        minSdkVersion 10
        targetSdkVersion 19
    }

    signingConfigs {
        mySignConfig {
            storeFile = file(project.property('storeFile'))
            storePassword = project.property('storePassword')
            keyAlias = project.property('keyAlias')
            keyPassword = project.property('keyPassword')
        }
    }

    productFlavors {
        open {
            applicationId 'com.projectsexception.myapplist.open'
        }

        play {
            applicationId 'com.projectsexception.myapplist'
            if (project.hasProperty('myapplist.ga_tracking_id')) {
                buildConfigField 'String', 'TRACKING_ID', '"' + project.property('myapplist.ga_tracking_id') + '"'
            } else {
                buildConfigField 'String', 'TRACKING_ID', '"xxx"'
            }
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix '.debug'
            versionNameSuffix '-debug'
            signingConfig signingConfigs.mySignConfig
        }

        release {
            signingConfig signingConfigs.mySignConfig
        }
    }

    lintOptions {
//        abortOnError false
    }

}

dependencies {
    compile (project (':dependencies:android-utils')) {
        exclude group: 'com.google.android'
    }
    // You must install or update the Support Repository through the SDK manager to use this dependency.
    compile 'com.android.support:support-v4:19.1.+'
    compile 'com.android.support:appcompat-v7:19.1.+'
    compile ('com.github.manuelpeinado.multichoiceadapter:multichoiceadapter-abc:3.1.+') {
        exclude group: 'com.android.support'
    }
    compile 'de.keyboardsurfer.android.widget:crouton:1.8.+@aar'
    compile 'com.jakewharton:butterknife:5.1.+'
    compile 'com.nineoldandroids:library:2.4.+'

    playCompile 'com.google.android.gms:play-services:5.0.+'
}

afterEvaluate { project ->
    android.applicationVariants.each { variant ->
        variant.javaCompile.dependsOn stripPlayServices
    }
}

task stripPlayServices << {
    def playServiceRootFolder = new File(rootProject.buildDir, "intermediates/exploded-aar/com.google.android.gms/play-services/")
    playServiceRootFolder.list().each { versionName ->
        def versionFolder = new File(playServiceRootFolder, versionName)
        copy {
            from(file(new File(versionFolder, "classes.jar")))
            into(file(versionFolder))
            rename { fileName ->
                fileName = "classes_orig.jar"
            }
        }
        tasks.create(name: "strip" + versionName, type: Jar) {
            destinationDir = versionFolder
            archiveName = "classes.jar"
            from(zipTree(new File(versionFolder, "classes_orig.jar"))) {
                exclude "com/google/ads/**"
                //exclude "com/google/android/gms/analytics/**"
                exclude "com/google/android/gms/games/**"
                exclude "com/google/android/gms/plus/**"
                exclude "com/google/android/gms/drive/**"
                //exclude "com/google/android/gms/ads/**"
            }
        }.execute()
        delete {
            delete(file(new File(versionFolder, "classes_orig.jar")))
        }
    }
}
