/*
 * Copyright 2013-2015 microG Project Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

apply plugin: 'com.android.application'

repositories {
    jcenter()
    flatDir {
        dirs '../libs'
    }
}

dependencies {
    compile 'de.hdodenhof:circleimageview:1.2.1'
    compile 'com.squareup.wire:wire-runtime:1.6.1'

    compile project(":microg-ui-tools")
    compile project(':play-services-api')
    compile project(':unifiednlp-base')
    compile project(':wearable-lib')

    // vtm from ./libs
    compile 'org.oscim:vtm-android:0.6.0-SNAPSHOT@aar'
    compile 'org.oscim:vtm-themes:0.6.0-SNAPSHOT@jar'
    compile 'org.oscim:vtm-extras:0.6.0-SNAPSHOT@jar'
    compile 'org.oscim:vtm:0.6.0-SNAPSHOT@jar'
    // Dependencies for vtm
    compile 'com.fasterxml.jackson.core:jackson-core:2.3.0'
    compile 'com.vividsolutions:jts:1.13'
    compile 'com.google.protobuf:protobuf-java:2.4.1'
    compile 'org.openstreetmap.osmosis:osmosis-osm-binary:0.43.1'
    compile 'org.slf4j:slf4j-android:1.7.6'
}

String getMyVersionName() {
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'describe', '--tags', '--always', '--dirty'
        standardOutput = stdout
    }
    return stdout.toString().trim()
}

int getMyVersionCode(String ref) {
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-list', '--count', "$ref..HEAD"
        standardOutput = stdout
    }
    return Integer.parseInt(stdout.toString().trim())
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        versionName getMyVersionName()
        def x = getMyVersionCode('249c935f')
        // We are not allowed to freely choose the hundreds column as it defines the device type
        // Update commit id to current when increasing gms version code
        versionCode(8490200 + x % 100 + ((int) (x / 100)) * 1000)

        ndk {
            abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86"
        }
    }

    sourceSets {
        main {
            java.srcDirs += 'src/main/protos-java'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
    }
    lintOptions {
        // TODO: Remove MissingTranslation once we have stable strings and proper translations.
        disable 'MissingTranslation', 'InvalidPackage'
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

if (file('user.gradle').exists()) {
    apply from: 'user.gradle'
}
