def activation = rootProject.childProjects.activation
def rootDir = activation.getRootDir()
def prebuilt = rootProject.rootDir.absolutePath + File.separator + 'prebuilt'

def pkgConf = [
        'jar'     : "${buildDir}/intermediates/shrunk_classes/release/shrunkClasses.jar",
        'activationjar'     : "${activation.buildDir}/intermediates/shrunk_classes/release/shrunkClasses.jar",
        'activationres'     : "${rootDir}/activation/src/main/res",
        'manifest': "${prebuilt}/AndroidManifest.xml",
        'res'     : 'src/main/res',
        'libs'    : 'libs',
        'so'      : "${buildDir}/intermediates/stripped_native_libs/release/out/lib",
        'adt'     : "${buildDir}/intermediates/adt",
        'dest'    : "${buildDir}/outputs/zip"
]

task adtArchive(type: Zip) {
    group '4399Single'
    dependsOn 'assembleRelease',  'jar', 'addPrebuilt', 'activationjar', 'so', 'deps', 'res','activationres', 'manifest'

    delete pkgConf.adt, pkgConf.dest
    from pkgConf.adt
    include '*/**'
    archiveName "4399SingleSDK-v${POM_VERSION}+${POM_BUILD_ID}.zip"
    destinationDir file(pkgConf.dest)
}

task jar(type: Copy) {
    from pkgConf.jar
    into "${pkgConf.adt}/libs"
    rename {
        "4399SingleSDK-v${POM_VERSION}+${POM_BUILD_ID}.jar"
    }
}

task activationjar(type: Copy) {
    from pkgConf.activationjar
    into "${pkgConf.adt}/libs"
    rename {
        "4399ActivationSDK-v${activation.POM_VERSION}+${activation.POM_BUILD_ID}.jar"
    }
}

task so(type: Copy) {
    from pkgConf.so
    into "${pkgConf.adt}/libs"
}

task addPrebuilt(type: Copy) {
    from "${prebuilt}/libs"
    into "${pkgConf.adt}/libs"
}

task deps(type: Copy) {
    from pkgConf.libs
    into "${pkgConf.adt}/libs"
    exclude 'aidl-classes-v1.0.0.jar'
    exclude 'alipaySdk-v15.5.5+20180601.jar'
}

task res(type: Copy) {
    from pkgConf.res
    into "${pkgConf.adt}/res"
}

task activationres(type: Copy) {
    from pkgConf.activationres
    into "${pkgConf.adt}/res"
}

task manifest(type: Copy) {
    from pkgConf.manifest
    into pkgConf.adt
}