//
// Copyright (c) 2016 eppz! mobile, Gergely Borbás (SP)
//
// http://www.twitter.com/_eppz
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    provided files('./libs/UnityPlayer.jar') // Avoid redundant Unity Player in final application APK
}

android.libraryVariants.all { variant ->

    // Task names.
    String variantName = "${variant.name.capitalize()}";
    String deployTaskGroup = "plugin";
    String deployTaskName = "deploy${variantName}PluginArchive";
    String dependencyTaskName = "assemble${variantName}";

    // Source.
    String sourceAARFolder = "${buildDir.getPath()}/outputs/aar/";
    String sourceAARName = "${project.name}-${variant.name}.aar";

    // Target.
    String targetAssetFolder = "Assets/Plugins/eppz! Alert";
    String targetAARFolder = "${rootDir.getPath()}/../../${targetAssetFolder}";
    String targetAARName = "eppz! Alert Android.aar";

    // Create task.
    task(deployTaskName, dependsOn: dependencyTaskName, type: Copy) {
        logger.lifecycle("${variant.name.capitalize()} AAR Folder: ${sourceAARFolder}")
        logger.lifecycle("${variant.name.capitalize()} Target AAR Folder: ${targetAARFolder}")
        logger.lifecycle("${variant.name.capitalize()} Target AAR name: ${targetAARName}")

        from(sourceAARFolder)
        into(targetAARFolder)
        include(sourceAARName)
        rename(sourceAARName, targetAARName)
    }.group = deployTaskGroup;
}