【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

相关推荐
Dnelic-2 小时前
Android 5G NR 状态类型介绍
android·5g·telephony·connectivity·自学笔记·移动网络数据
吗喽对你问好4 小时前
Android UI 控件详解实践
android·ui
东风西巷7 小时前
X-plore File Manager v4.34.02 修改版:安卓设备上的全能文件管理器
android·网络·软件需求
yzpyzp7 小时前
Android 15中的16KB大页有何优势?
android
安卓开发者7 小时前
Android Room 持久化库:简化数据库操作
android·数据库
程序视点7 小时前
FadCam安卓后台录制神器:2025最全使用指南(开源/免费/息屏录制)
android
猿小蔡8 小时前
Android ADB命令之内存统计与分析
android
游戏开发爱好者89 小时前
没有 Mac,如何上架 iOS App?多项目复用与流程标准化实战分享
android·ios·小程序·https·uni-app·iphone·webview
你过来啊你10 小时前
Android开发中nfc协议分析
android
Auspemak-Derafru11 小时前
安卓上的迷之K_1171477665
android