apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.androidCompileSdkVersion
    defaultConfig {
        applicationId "org.lsposed.lspatch"
        minSdkVersion rootProject.ext.androidMinSdkVersion
        targetSdkVersion rootProject.ext.androidTargetSdkVersion
        versionCode rootProject.ext.verCode
        versionName rootProject.ext.verName

        multiDexEnabled false
    }
    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
    applicationVariants.all { variant ->
        def buildType = variant.name.capitalize()
        def variantLowered = variant.name.toLowerCase()

        variant.outputs.all {
            outputFileName = "${variant.getFlavorName()}-${variant.versionName}.apk"
        }

        task "copyDex$buildType"(type: Copy) {
            dependsOn("assemble$buildType")
            def dexFilePath = "$buildDir/intermediates/dex/${variantLowered}/mergeDex${buildType}/classes.dex"
            from dexFilePath
            rename "(.*).dex", "classes-${version_name}.dex"
            into "$rootProject.projectDir/out/list-dex"
        }

        task "copySo$buildType"(type: Copy) {
            dependsOn("assemble$buildType")
            from "$buildDir/intermediates/merged_native_libs/${variantLowered}/out/lib"
            into "$rootProject.projectDir/out/list-so"
        }

        task "copy$buildType"() {
            dependsOn("copySo$buildType")
            dependsOn("copyDex$buildType")

            doLast {
                System.out.println("Dex and so files has been copy to ${rootProject.projectDir}${File.separator}out")
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(path: ':lspcore')
}
