【Gradle】Build Multiple Android Variants in Groovy

Gradle Script

app/build.gradle

groovy 复制代码
flavorDimensions("market", "version")

productFlavors {
    create("HUAWEI") {
        dimension = "market"
        manifestPlaceholders["market"] = name
    }
    create("HONOR") {
        dimension = "market"
        manifestPlaceholders["market"] = name
    }
    create("1_0_0") {
        dimension = "version"
        versionCode = 6000
        versionName = "1.0.0"
        manifestPlaceholders["version"] = versionName
    }
    create("2_0_0") {
        dimension = "version"
        versionCode = 7000
        versionName = "2.0.0"
        manifestPlaceholders["version"] = versionName
    }
}

buildTypes {
    debug {
        manifestPlaceholders = []
    }
}

variantFilter { variant ->
    if (variant.buildType.name.endsWith('release')) {
        variant.setIgnore(true)
    }
}

applicationVariants.all { variant ->
    def market = variant.productFlavors.find { it.dimension == "market" }.name
    def version = variant.productFlavors.find { it.dimension == "version" }.name.replaceAll("_", ".")
    variant.outputs.all { output ->
        output.outputFileName = "${market}-${version}.apk"
    }
}
Build Multiple Apks

Build - Generate Signed APK

相关推荐
CYRUS_STUDIO23 分钟前
Android 加壳应用运行流程 与 生命周期类处理方案
android·安全·逆向
隐-梵26 分钟前
Android studio进阶开发(四)--okhttp的网络通信的使用
android·ide·okhttp·android studio
_一条咸鱼_32 分钟前
Android大厂面试通关秘籍
android·面试·android jetpack
zhishishe3 小时前
2025 年免费 Word 转 PDF 转换器有哪些?
android·windows·pdf·电脑·word
Ya-Jun9 小时前
常用第三方库精讲:cached_network_image图片加载优化
android·flutter
_一条咸鱼_9 小时前
Android嵌套滑动详解
android·面试·android jetpack
zhishishe11 小时前
工具指南:免费将 PDF 转换为 Word 的 10 个工具
android·windows·pdf·word
孙同学_11 小时前
【MySQL】004.MySQL数据类型
android·数据库·mysql
流浪汉kylin14 小时前
Android 图片选择器改系统
android
前行的小黑炭14 小时前
Android 上下位机开发:串口是什么,为什么android版本都比较低?粘包半包的原因以及处理思路,缓冲区处理,以及超时清空缓冲区....
android