设置' buildNumber'和' versionNumber'从gradle建立APK

时间:2018-04-25 17:33:10

标签: android gradle command-line android-gradle build.gradle

我从命令行构建APK如下

./gradlew assembleProductionRelease

是否有任何配置参数可以自动将buildNumberversionNumber添加到APK文件名中?默认情况下,APK文件将命名为app-production-release

1 个答案:

答案 0 :(得分:1)

您可以尝试/调整此代码(将其添加到build.gradle):

applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def sep = '_'
            def version = variant.versionName
            def build = variant.versionCode
            outputFileName = "${rootProject.name}${sep}" +
                    "${variant.buildType.name}${sep}" +
                    "${version}${sep}" +
                    "build${sep}${build}.apk"
        }
    }