// This comment exists for a reason, do not delete
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' // kotlin
apply plugin: 'kotlin-parcelize'
apply plugin: 'com.google.devtools.ksp'
apply plugin: 'kotlin-kapt'
apply plugin: 'therouter'

import groovy.xml.XmlUtil

android {

    String CONFIG_ID = ""
    String FIRST_LAUNCH = ""
    String SDK_VERSION = ""
    String SDK_APP_ID = ""
    String SDK_APP_NAME = ""
    boolean USE_DEFAULT_CHANNEL_SDK = true
    int ACTIVATE_REPORTING_RATIO = 100

    buildFeatures {
        viewBinding true
        dataBinding true
    }

    compileOptions {
        coreLibraryDesugaringEnabled true

        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    dexOptions {
//        jumboMode = true
        javaMaxHeapSize "4g"
        preDexLibraries true
        maxProcessCount 8
    }

    aaptOptions {
        additionalParameters "--no-version-vectors"
    }

    kapt {
        useBuildCache = true
        javacOptions {
            // 增加注解处理器的最大错误次数,默认为 100
            option("-Xmaxerrs", 500)
        }
    }

    ksp {
        arg("ROUTER_MODULE_NAME", project.getName())
    }

    defaultConfig {
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true

        ndk {
            // x86 本来是为了模拟器用户使用 RenderScript 用的，但是其实用到 RenderScript 的人本来就不多 (一天不到 100)，用模拟器的人就更少了
            // 加了 x86 反而会导致用户没法使用微博登录，因为微博没有提供 x86 的 SO ...
            // 还会增大 APK 体积，所以还是去掉吧。数据可见 https://sentry.shanqu.cc/organizations/lightgame/issues/144232/?project=22
            abiFilters "armeabi-v7a", "arm64-v8a"
        }

        renderscriptTargetApi 18
        renderscriptSupportModeEnabled true

        // 由于app只针对中文用户，所以仅保留zh资源，其他删掉
        resConfigs "zh"

        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName
        applicationId rootProject.ext.applicationId

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt', 'proguard-fresco.txt', rootProject.ext.va_proguard_rules

        String CORE_EVENT_GAME_CATEGORY = ""

        // 推广用的关键事件游戏类型
        buildConfigField "String", "CORE_EVENT_GAME_CATEGORY", "\"${CORE_EVENT_GAME_CATEGORY}\""

        // 推广用的配置 id
        buildConfigField "String", "CONFIG_ID", "\"${CONFIG_ID}\""

        // 推广用的 SDK 版本 （仅记录使用）
        buildConfigField "String", "SDK_VERSION", "\"${SDK_VERSION}\""
        buildConfigField "String", "SDK_APP_ID", "\"${SDK_APP_ID}\""
        buildConfigField "String", "SDK_APP_NAME", "\"${SDK_APP_NAME}\""
        buildConfigField "boolean", "USE_DEFAULT_CHANNEL_SDK", "${USE_DEFAULT_CHANNEL_SDK}"

        // 首次启动的跳转配置
        buildConfigField "String", "FIRST_LAUNCH", "\"${FIRST_LAUNCH}\""

        buildConfigField "int", "ACTIVATE_REPORTING_RATIO", "${ACTIVATE_REPORTING_RATIO}"

        // All third-party appid/appkey
        buildConfigField "boolean", "IS_GAT_APP", "false"
        buildConfigField "String", "API_HOST", "\"${API_HOST}\""
        buildConfigField "String", "NEW_API_HOST", "\"${NEW_API_HOST}\""
        buildConfigField "String", "LOG_HUB_PROJECT", "\"${LOG_HUB_PROJECT}\""
        buildConfigField "String", "VAPI_HOST", "\"${VAPI_HOST}\""
        buildConfigField "String", "WGAME_CPM_BUSIAPPID", "\"${WGAME_CPM_BUSIAPPID}\""
        buildConfigField "String", "WGAME_CPM_API_HOST", "\"${WGAME_CPM_API_HOST}\""
        buildConfigField "String", "WECHAT_APPID", "\"${WECHAT_APPID}\""
        buildConfigField "String", "WECHAT_SECRET", "\"${WECHAT_SECRET}\""
        buildConfigField "String", "TENCENT_APPID", "\"${TENCENT_APPID}\""
        buildConfigField "String", "WEIBO_APPKEY", "\"${WEIBO_APPKEY}\""
        buildConfigField "String", "DSP_API_HOST","\"${DSP_API_HOST}\""
        // 一体包的32位畅玩游戏助手包名
        buildConfigField "String", "EXT_PACKAGE_NAME", "\"${rootProject.ext.EXT_PACKAGE_NAME}\""
    }

    // gradle 2.2以上默认同时启用v1和v2（优先用于Android N）
    signingConfigs {
        debug {
            v1SigningEnabled true
            v2SigningEnabled true
        }
        release {
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }

    packagingOptions {
        // exclude 部分冗余的文件
        exclude 'META-INF/gradle/incremental.annotation.processors'
        exclude 'darwin/x86_64/liblz4-java.dylib'

        exclude 'assets/libwbsafeedit_x86'
        exclude 'assets/libwbsafeedit_x86_64'

        exclude 'lib/armeabi-v7a/libRSSupport.so'
        exclude 'lib/arm64-v8a/libRSSupport.so'
        exclude 'lib/armeabi-v7a/librsjni.so'
        exclude 'lib/arm64-v8a/librsjni.so'

        resources.excludes += "com/j256/*"
        resources.excludes += "org/apache/commons/codec/language/bm/*"
    }

    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            zipAlignEnabled false
            signingConfig signingConfigs.debug

            buildConfigField "String", "EXPOSURE_REPO", "\"exposure\""
            buildConfigField "String", "EXPOSURE_VERSION", "\"E4\""

            multiDexKeepProguard file("tinker_multidexkeep.pro")
        }
        release {
            debuggable false
            minifyEnabled true
            zipAlignEnabled true
            shrinkResources true
            signingConfig signingConfigs.release

            buildConfigField "String", "EXPOSURE_REPO", "\"exposure\""
            buildConfigField "String", "EXPOSURE_VERSION", "\"E4\""

            multiDexKeepProguard file("tinker_multidexkeep.pro")
        }
    }

    // Ignore useless variant
    variantFilter { variant ->
        def names = variant.flavors*.name
        def isDebugType = variant.buildType.name == "debug"
        if ((names.contains("tea") || name.contains("kuaishou") || name.contains("gdt")) && isDebugType) {
            setIgnore(true)
        }
    }

    flavorDimensions("env", "region")

    sourceSets {

        debug {
            assets.srcDirs += 'src/main/assets-debug'
        }

        release {
            assets.srcDirs += 'src/main/assets-release'
        }

        publish {
            java.srcDirs = ['src/main/java', "src/default/java"]
        }
        internal {
            java.srcDirs = ['src/main/java', "src/default/java", "src/internal/java"]
        }
        tea {
            java.srcDirs = ['src/main/java', 'src/tea/java']
        }
        kuaishou {
            java.srcDirs = ['src/main/java', 'src/kuaishou/java']
        }
        gdt {
            java.srcDirs = ['src/main/java', 'src/gdt/java']
        }
        gat {
            java.srcDirs = ['src/main/java', 'src/gat/java']
        }
        cn {
            java.srcDirs = ['src/main/java', 'src/cn/java']
        }
        sm {
            java.srcDirs = ['src/main/java', 'src/sm/java']
        }
    }

    productFlavors {
        // internal， 内部测试包使用的 flavor，接口包含包括测试和正式环境
        internal {
            dimension "env"
            versionNameSuffix "-debug"

            buildConfigField "String", "DEV_API_HOST", "\"${DEV_API_HOST}\""
            buildConfigField "String", "NEW_DEV_API_HOST", "\"${NEW_DEV_API_HOST}\""
            buildConfigField "String", "DEV_VAPI_HOST", "\"${DEV_VAPI_HOST}\""
            buildConfigField "String", "QUICK_LOGIN_APPID", "\"${DEV_QUICK_LOGIN_APPID}\""
            buildConfigField "String", "QUICK_LOGIN_APPKEY", "\"${DEV_QUICK_LOGIN_APPKEY}\""
            buildConfigField "String", "DEV_CSJ_APPID", "\"${DEV_CSJ_APPID}\""
            buildConfigField "String", "CSJ_APPID", "\"${CSJ_APPID}\""

            buildConfigField "String", "VA_VERSION_NAME", "\"${rootProject.ext.VA_VERSION}-debug\""
            manifestPlaceholders.put("VA_VERSION_NAME", "${rootProject.ext.VA_VERSION}-debug")
        }

        // publish， 发布时候使用的 flavor，接口仅包含正式环境
        publish {
            dimension "env"

            buildConfigField "String", "DEV_API_HOST", "\"${API_HOST}\""
            buildConfigField "String", "NEW_DEV_API_HOST", "\"${NEW_API_HOST}\""
            buildConfigField "String", "DEV_VAPI_HOST", "\"${VAPI_HOST}\""
            buildConfigField "String", "QUICK_LOGIN_APPID", "\"${QUICK_LOGIN_APPID}\""
            buildConfigField "String", "QUICK_LOGIN_APPKEY", "\"${QUICK_LOGIN_APPKEY}\""
            buildConfigField "String", "DEV_CSJ_APPID", "\"${CSJ_APPID}\""
            buildConfigField "String", "CSJ_APPID", "\"${CSJ_APPID}\""

            buildConfigField "String", "VA_VERSION_NAME", "\"${rootProject.ext.VA_VERSION}\""
            manifestPlaceholders.put("VA_VERSION_NAME", "${rootProject.ext.VA_VERSION}")
        }

        tea {
            dimension "env"

            buildConfigField "String", "DEV_API_HOST", "\"${API_HOST}\""
            buildConfigField "String", "NEW_DEV_API_HOST", "\"${NEW_API_HOST}\""
            buildConfigField "String", "DEV_VAPI_HOST", "\"${VAPI_HOST}\""
            buildConfigField "String", "QUICK_LOGIN_APPID", "\"${QUICK_LOGIN_APPID}\""
            buildConfigField "String", "QUICK_LOGIN_APPKEY", "\"${QUICK_LOGIN_APPKEY}\""
            buildConfigField "String", "DEV_CSJ_APPID", "\"${CSJ_APPID}\""
            buildConfigField "String", "CSJ_APPID", "\"${CSJ_APPID}\""

            buildConfigField "String", "VA_VERSION_NAME", "\"${rootProject.ext.VA_VERSION}\""

            manifestPlaceholders.put("APPLOG_SCHEME", "rangersapplog.byAx6uYt".toLowerCase())
            manifestPlaceholders.put("VA_VERSION_NAME", "${rootProject.ext.VA_VERSION}")
        }

        kuaishou {
            dimension "env"

            buildConfigField "String", "DEV_API_HOST", "\"${API_HOST}\""
            buildConfigField "String", "NEW_DEV_API_HOST", "\"${NEW_API_HOST}\""
            buildConfigField "String", "DEV_VAPI_HOST", "\"${VAPI_HOST}\""
            buildConfigField "String", "QUICK_LOGIN_APPID", "\"${QUICK_LOGIN_APPID}\""
            buildConfigField "String", "QUICK_LOGIN_APPKEY", "\"${QUICK_LOGIN_APPKEY}\""
            buildConfigField "String", "DEV_CSJ_APPID", "\"${CSJ_APPID}\""
            buildConfigField "String", "CSJ_APPID", "\"${CSJ_APPID}\""

            buildConfigField "String", "VA_VERSION_NAME", "\"${rootProject.ext.VA_VERSION}\""
            manifestPlaceholders.put("VA_VERSION_NAME", "${rootProject.ext.VA_VERSION}")
        }

        gdt {
            dimension "env"

            buildConfigField "String", "DEV_API_HOST", "\"${API_HOST}\""
            buildConfigField "String", "NEW_DEV_API_HOST", "\"${NEW_API_HOST}\""
            buildConfigField "String", "DEV_VAPI_HOST", "\"${VAPI_HOST}\""
            buildConfigField "String", "QUICK_LOGIN_APPID", "\"${QUICK_LOGIN_APPID}\""
            buildConfigField "String", "QUICK_LOGIN_APPKEY", "\"${QUICK_LOGIN_APPKEY}\""
            buildConfigField "String", "DEV_CSJ_APPID", "\"${CSJ_APPID}\""
            buildConfigField "String", "CSJ_APPID", "\"${CSJ_APPID}\""

            buildConfigField "String", "VA_VERSION_NAME", "\"${rootProject.ext.VA_VERSION}\""
            manifestPlaceholders.put("VA_VERSION_NAME", "${rootProject.ext.VA_VERSION}")
        }

        sm {
            dimension "env"

            buildConfigField "String", "DEV_API_HOST", "\"${API_HOST}\""
            buildConfigField "String", "NEW_DEV_API_HOST", "\"${NEW_API_HOST}\""
            buildConfigField "String", "DEV_VAPI_HOST", "\"${VAPI_HOST}\""
            buildConfigField "String", "QUICK_LOGIN_APPID", "\"${QUICK_LOGIN_APPID}\""
            buildConfigField "String", "QUICK_LOGIN_APPKEY", "\"${QUICK_LOGIN_APPKEY}\""
            buildConfigField "String", "DEV_CSJ_APPID", "\"${CSJ_APPID}\""
            buildConfigField "String", "CSJ_APPID", "\"${CSJ_APPID}\""

            buildConfigField "String", "VA_VERSION_NAME", "\"${rootProject.ext.VA_VERSION}\""
            manifestPlaceholders.put("VA_VERSION_NAME", "${rootProject.ext.VA_VERSION}")
        }

        // 港澳台
        gat {
            dimension "region"

            applicationId rootProject.ext.applicationIdGat

            // 支持繁体
            resConfigs "zh", "zh-rTW"

            buildConfigField "boolean", "IS_GAT_APP", "true"
            buildConfigField "String", "LOG_HUB_PROJECT", "\"${LOG_HUB_PROJECT_GAT}\""
            buildConfigField "String", "API_HOST", "\"${API_HOST_GAT}\""
            buildConfigField "String", "NEW_API_HOST", "\"${NEW_API_HOST_GAT}\""
        }

        cn {
            dimension "region"
        }
    }
}

repositories {
    flatDir {
        dirs 'libs', 'libs/aars'
    }
}

// 删除不需要的 assets
android.applicationVariants.configureEach { variant ->
    variant.mergeAssets.doLast {
        def assetDir = variant.mergeAssetsProvider.get().outputDir.get()
        def unwantedAssets = ['1832823466', 'gdt_plugin/gdtadv2.jar']

        unwantedAssets.each { assetPath ->
            def file = new File([assetDir, assetPath].join(File.separator))
            if (file.exists()) {
                file.delete()
            }
        }
    }
}

dependencies {

    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')

    teaImplementation fileTree(include: ['*.jar', '*.aar'], dir: 'src/tea/libs')
    kuaishouImplementation fileTree(include: ['*.jar', '*.aar'], dir: 'src/kuaishou/libs')
    gdtImplementation fileTree(include: ['*.jar', '*.aar'], dir: 'src/gdt/libs')
    smImplementation fileTree(include: ['*.jar', '*.aar'], dir: 'src/sm/libs')

    debugImplementation "com.squareup.leakcanary:leakcanary-android:${leakcanary}"
    debugImplementation "com.squareup.leakcanary:leakcanary-android-process:${leakcanary}"

//    debugImplementation "com.gu.android:toolargetool:${toolargetool}" // 需要使用调试时才启用
    debugImplementation "com.github.nichbar:WhatTheStack:${whatTheStack}"

    implementation "androidx.multidex:multidex:${multiDex}"
    implementation "androidx.fragment:fragment-ktx:${fragment}"

    implementation "androidx.annotation:annotation:${annotation}"

    implementation "androidx.viewpager2:viewpager2:${viewpager2}"
    ksp("androidx.room:room-compiler:${room}")

    implementation "com.tencent.vasdolly:helper:${apkChannelPackage}"
    implementation "com.tencent.vasdolly:writer:${apkChannelPackage}"

    implementation "com.j256.ormlite:ormlite-android:${ormlite}"
    implementation "com.j256.ormlite:ormlite-core:${ormlite}"

    implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation "com.contrarywind:Android-PickerView:${pickerView}"

    implementation "net.cachapa.expandablelayout:expandablelayout:${expandableLayout}"

    // 用于比较 versionName 是大于小于或等于
    implementation "com.g00fy2:versioncompare:${versioncompare}"

    // for video streaming
    implementation("com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-java:$gsyVideo", {
        exclude module: "gsyvideoplayer-androidvideocache"
        exclude group: "tv.danmaku.ijk.media"
    })
    implementation("com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-exo_player2:$gsyVideo") {
        exclude group: 'com.google.android.exoplayer', module: 'extension-rtmp'
    }

    implementation "com.llew.huawei:verifier:${verifier}"

    teaImplementation "com.bytedance.applog:RangersAppLog-Lite-cn:${bytedanceApplog}"
    teaImplementation "com.bytedance.ads:AppConvert:${bytedanceAppConvert}"

    implementation "net.lingala.zip4j:zip4j:${zip4j}"

    implementation "com.github.hsiafan:apk-parser:${apkParser}"
    implementation "org.nanohttpd:nanohttpd:${nanohttpd}"

    implementation "com.lg:easyfloat:${easyFloat}"

    implementation("com.lg:apksig:${apksig}") {
        exclude group: 'com.google.protobuf'
    }

    implementation "com.lg:gid:${gid}"

    implementation "com.lg:shortcut:${shortcut}"

    coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:${desugarJdkLibs}"

    kapt "com.google.auto.service:auto-service:${autoServiceVersion}"
    ksp "cn.therouter:apt:${routerVersion}"

    implementation project(':ndownload')
    implementation project(':vspace-bridge:vspace')
    implementation(project(':feature:xapk-installer'))

    implementation(project(':module_common')) {
        exclude group: 'androidx.swiperefreshlayout'
    }

    implementation(project(':module_login')) {
        exclude group: 'androidx.swiperefreshlayout'
    }

    implementation(project(':module_core_feature')) {
        exclude group: 'androidx.swiperefreshlayout'
    }

    implementation(project(':module_setting')) {
        exclude group: 'androidx.swiperefreshlayout'
    }

//    implementation(project(':module_setting_compose')) {
//        exclude group: 'androidx.swiperefreshlayout'
//    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enablePkg) {
        implementation(project(':feature:pkg'))
    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableFeedback) {
        implementation(project(':feature:new_feedback')) {
            exclude group: 'androidx.swiperefreshlayout'
        }
    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableMessage) {
        implementation(project(':module_message')) {
            exclude group: 'androidx.swiperefreshlayout'
        }
    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableOaid) {
        implementation(project(':feature:oaid'))
    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableFloatingWindow) {
        implementation(project(':feature:floating-window'))
    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableSensorData) {
        implementation(project(':module_sensors_data')) {
            exclude group: 'androidx.swiperefreshlayout'
        }
    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableCsjAd) {
        implementation(project(':feature:csj_ad'))
    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableQQGame) {
        implementation(project(':feature:qq_game')) {
            exclude group: 'androidx.swiperefreshlayout'
        }
    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enablePush) {
        def pushProperty = findProperty('BUILD_PUSH_TYPE')
        // 根据BUILD_PUSH_TYPE决定使用哪个推送SDK，目前默认使用极光推送
        def pushProject = (pushProperty == null || pushProperty == 'jg')
                ? project(':feature:jg_push') : project(':feature:acloud_push')

        implementation(pushProject) {
            exclude group: 'androidx.swiperefreshlayout'
        }
    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableSentry) {
        implementation(project(':feature:sentry'))
    }

    if (gradle.ext.enableRouteDoc) {
        ksp project(":feature:route_doc")
    }

    implementation(project(':feature:media_select'))

    implementation(project(":module_va_api"))
    implementation(project(":va-archive-common"))
    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableVa) {
        implementation(project(":module_va_impl"))
    }
    debugImplementation "com.bytedance.tools.codelocator:codelocator-core:2.0.3"
    internalImplementation(project(':module_internal_test'))

    debugImplementation 'com.bytedance.android:shadowhook:1.0.9'
    debugImplementation 'io.github.shiqos:wytrace:1.0.1'

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableAccelerator) {
        implementation(project(":feature:accelerator"))
    }

    if (!gradle.ext.excludeOptionalModules || gradle.ext.enableAliPay) {
        implementation(project(":feature:ali_pay"))
    }

    if(!gradle.ext.excludeOptionalModules || gradle.ext.enableWechatPay){
        implementation(project(":feature:wechat_pay"))
    }

    implementation "me.xdrop:fuzzywuzzy:${fuzzyVersion}"
}

File propFile = file('sign.properties')
if (propFile.exists()) {
    Properties props = new Properties()
    props.load(new FileInputStream(propFile))

    if (props.containsKey('keyAlias') && props.containsKey('keyPassword') &&
            props.containsKey('storeFile') && props.containsKey('storePassword')) {
        android.signingConfigs {
            // debug 不要使用正式签名，这样tinker才不会打补丁。
            debug {
                keyAlias props.get('keyAlias')
                keyPassword props.get('keyPassword')
                storeFile file(props.get('storeFile'))
                storePassword props.get('storePassword')
            }
            release {
                keyAlias props.get('keyAlias')
                keyPassword props.get('keyPassword')
                storeFile file(props.get('storeFile'))
                storePassword props.get('storePassword')
            }
        }
    } else {
        android.buildTypes.release.signingConfig = null
    }
} else {
    android.buildTypes.release.signingConfig = null
}

// 用于测试读取 META-INF 里的文件
//task generateMetaJson {
//    def resDir = new File(buildDir, 'generated/FILES_FOR_META_INF/')
//    def destDir = new File(resDir, 'META-INF/')
//    // Add resDir as a resource directory so that it is automatically included in the APK.
//    android {
//        sourceSets {
//            main.resources {
//                srcDir resDir
//            }
//        }
//    }
//
//    doLast {
//        if (!destDir.exists()) destDir.mkdirs()
//        copy {
//            into destDir
//            from new File('generated/FILES_FOR_META_INF/META-INF/halo_skip.json')
//        }
//    }
//}
//// Specify when put_files_in_META_INF should run
//project.afterEvaluate {
//    tasks.findAll { task ->
//        task.name.startsWith('merge') && task.name.endsWith('Resources')
//    }.each { t -> t.dependsOn generateMetaJson }
//}

project.afterEvaluate {
    def variants = null
    try {
        variants = android.applicationVariants
    } catch (Throwable t) {
        t.printStackTrace()
        try {
            variants = android.libraryVariants
        } catch (Throwable tt) {
            tt.printStackTrace()
        }
    }
    if (variants != null) {
        variants.all { variant ->
            variant.outputs.each { output ->
                def task = output.processManifestProvider.get()
                if (task == null) {
                    return
                }

                /**
                 * 为 Manifest 的 Activity 的 configChanges 添加自己手动处理 configurationChanges 配置 [https://developer.android.com/guide/topics/resources/runtime-changes]
                 * AGP 4.1.0 从 ProcessManifest task 里拿 manifest 的 API 变更调整可以参考这里 [https://github.com/Tencent/tinker/pull/1476/commits/d71645729b13d545ca4ba6826f93fbf558751434]
                 * (搞半天还是不会抽离方法，有空再把 gradle 改成用 kotlin 实现吧)
                 */
                task.doLast {
                    def manifestFile = new File(multiApkManifestOutputDirectory.get().asFile, "AndroidManifest.xml")
                    if (manifestFile == null || !manifestFile.exists()) {
                        return
                    }

                    String[] configChanges = [
                            "density",
                            "fontScale",
                            "keyboard",
                            "keyboardHidden",
                            "layoutDirection",
                            "locale",
                            "mcc",
                            "mnc",
                            "navigation",
                            "orientation",
                            "screenLayout",
                            "screenSize",
                            "smallestScreenSize",
                            "touchscreen",
                            "uiMode"]

                    def parser = new XmlSlurper(false, true)
                    def manifest = parser.parse(manifestFile)
                    def app = manifest.'application'[0]
                    app.'activity'.each { act ->
                        String value = act.attributes()['android:configChanges']
                        if (value == null || value.isEmpty()) {
                            if (value == null) value = ""
                            configChanges.eachWithIndex { config, index ->
                                if (index != configChanges.length - 1) {
                                    value += config + "|"
                                } else {
                                    value += config
                                }
                            }
                            act.attributes()['androidconfigChanges'] = value
                        } else {
                            String[] valueSplit = value.split("\\|")
                            println configChanges
                            configChanges.eachWithIndex { config, index ->
                                if (!valueSplit.contains(config)) {
                                    value += ("|" + config)
                                }
                            }
                            act.attributes()['android:configChanges'] = value
                        }
                    }

                    def tmpManifest = XmlUtil.serialize(manifest).replaceAll("androidconfigChanges", "android:configChanges")
                    manifest = parser.parseText(tmpManifest)
                    manifestFile.setText(XmlUtil.serialize(manifest), "utf-8")
                }
            }
        }
    }
}