美文网首页
控制输出 apk aab的文件名称

控制输出 apk aab的文件名称

作者: toExploreFuture | 来源:发表于2022-11-02 08:20 被阅读0次
    // set the application output file name apk and aab
        applicationVariants.all {
    
            //set output apk name
            outputs.map {
                it as com.android.build.gradle.internal.api.BaseVariantOutputImpl
            }.forEach { output ->
                val bundleName = getBundleName(name)
                output.outputFileName = "${bundleName}-v$versionName($versionCode).apk"
            }
    
            //set output aab name
            outputs.all {
                // AAB file name that You want. Falvor name also can be accessed here.
                val bundleName = getBundleName(name)
                val aabPackageName = "${bundleName}-v$versionName($versionCode).aab"
    
                // Get final
                // bundle task name for this variant
                val bundleFinalizeTaskName = StringBuilder("sign").run {
                    // Add each flavor dimension for this variant here
                    productFlavors.forEach {
                        append(it.name.capitalizeAsciiOnly())
                    }
                    // Add build type of this variant
                    append(buildType.name.capitalizeAsciiOnly())
                    append("Bundle")
                    toString()
                }
    
                tasks.named(
                    bundleFinalizeTaskName, com.android.build.gradle.internal.tasks.FinalizeBundleTask::class.java
                ) {
                    val file = finalBundleFile.asFile.get()
                    val finalFile = File(file.parentFile, aabPackageName)
                    finalBundleFile.set(finalFile)
                }
            }
        }
    
    
    fun getBundleName(flavorName: String): String {
        if (flavorName.contains("bangladesh_we")) {
            return "孟加拉-天润业"
        } else if (flavorName.contains("bangladesh")) {
            return "孟加拉"
        } else if (flavorName.contains("indonesia_jakarta")) {
            return "印度尼西亚_雅加达"
        } else if (flavorName.contains("indonesia")) {
            return "印度尼西亚"
        } else if (flavorName.contains("columbia_two")) {
            return "哥伦比亚2"
        } else if (flavorName.contains("columbia")) {
            return "哥伦比亚"
        } else if (flavorName.contains("brazil")) {
            return "巴西"
        } else if (flavorName.contains("nigeria")) {
            return "尼日利亚"
        } else if (flavorName.contains("pakistan")) {
            return "巴基斯坦"
        } else if (flavorName.contains("mexico")) {
            return "墨西哥"
        } else if (flavorName.contains("peru")) {
            return "秘鲁"
        }
        return "LoansOne"
    }
    

    相关文章

      网友评论

          本文标题:控制输出 apk aab的文件名称

          本文链接:https://www.haomeiwen.com/subject/mcwstdtx.html