/*
 * Copyright (C) 2014 Snowdream Mobile <yanghui1986527@gmail.com>
 *
 * 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.
 */

apply plugin: 'android'

dependencies {
}

android {
    compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VERSION)
    buildToolsVersion project.BUILD_TOOLS_VERSION

    defaultConfig {
        versionCode Integer.parseInt(project.VERSION_CODE)
        versionName project.VERSION_NAME
        minSdkVersion Integer.parseInt(project.MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(project.TARGET_SDK_VERSION)
    }

//    signingConfigs {
//        release {
//            storeFile file(System.getenv("KEYSTORE"))
//            storePassword System.getenv("KEYSTORE_PASSWORD")
//            keyAlias System.getenv("KEY_ALIAS")
//            keyPassword System.getenv("KEY_PASSWORD")
//        }
//    }

    buildTypes {
//        release {
//            signingConfig signingConfigs.release
//        }
        debug {
            versionNameSuffix '-dev'
        }
    }

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

android.applicationVariants.all { variant ->
    def apk = variant.packageApplication.outputFile;
    def newName = "";

    newName = apk.name.replace(project.name, POM_NAME + "-v" + android.defaultConfig.versionName);
    newName = newName.replace("-" + variant.buildType.name, "");
    newName = newName.replace(".apk", "-" + variant.buildType.name.toLowerCase() + ".apk");

    variant.packageApplication.outputFile = new File(apk.parentFile, newName);
    if (variant.zipAlign) {
        variant.zipAlign.outputFile = new File(apk.parentFile, newName.replace("-unaligned", ""));
    }
}
