如何添加使用0.14+版本的Andr​​oid摇篮插件的版本号到我的APK文件? [英] How do I add a version number to my APK files using 0.14+ versions of the Android Gradle plugin?

查看:100
本文介绍了如何添加使用0.14+版本的Andr​​oid摇篮插件的版本号到我的APK文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有的versionName 包含在输出的名义APK文件从我的Andr​​oid版本。

I want to have the versionName included in the name of the output APK files from my Android build.

这里有一个另一个答案与pre-0.14.x工作插件版本,但他们改变了一些数据模型,使不工作了,我无法弄清楚如何解决它。据我所知,code的下方大块应该工作,但去年设置()调用似乎没有任何效果。它不会抛出一个错误,但价值也不会被取代。

There's an another answer that works with pre-0.14.x plugin versions, but they changed some of the data model so that doesn't work anymore, and I couldn't figure out how to fix it. As far as I can tell, the below chunk of code should work, but that last set() call appears to have no effect. It doesn't throw an error, but the value isn't replaced either.

buildTypes {
    applicationVariants.all { variant ->
        def oldFile = variant.outputs.outputFile.get(0)
        def newFile = new File(
                oldFile.parent,
                oldFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))

        variant.outputs.outputFile.set(0, newFile)
}

有人可以帮我这个?

Can someone help me out with this?

推荐答案

您现在需要多一个循环,每个变种可以有多个输出:

You need one more loop now that each variant can have multiple outputs:

android {
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.outputFile = new File(
                    output.outputFile.parent,
                    output.outputFile.name.replace(".apk", "-${variant.versionName}.apk"))
        }
    }
}

这篇关于如何添加使用0.14+版本的Andr​​oid摇篮插件的版本号到我的APK文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆