apply plugin: 'com.android.application'

repositories {
    jcenter()
}

android {
    compileSdkVersion androidCompileSdkVersion.toInteger()
    ndkVersion androidCompileNdkVersion
}

afterEvaluate {
    android.applicationVariants.all { variant ->
        def variantNameCapped = variant.name.capitalize()
        def variantNameLowered = variant.name.toLowerCase()

        task("copyDex${variantNameCapped}", type: Copy) {
            dependsOn "assemble${variantNameCapped}"
            def dexOutPath = "${buildDir}/intermediates/dex/${variantNameLowered}/mergeDex${variantNameCapped}"
            from (dexOutPath){
                rename("classes.dex", "eddalvikdx.dex")
            }
            destinationDir file(templateRootPath + "system/framework/")
            outputs.upToDateWhen { false }
        }
        task("makeJar${variantNameCapped}", type: Jar, dependsOn: "assemble${variantNameCapped}") {
            dependsOn "assemble${variantNameCapped}"
            from "${buildDir}/intermediates/javac/${variantNameLowered}/classes"
            baseName "dalvikdx"
            outputs.file(archivePath)
        }
    }
}
