如何用摇篮的APK文件名设置VERSIONNAME? [英] How to set versionName in APK filename using gradle?

查看:154
本文介绍了如何用摇篮的APK文件名设置VERSIONNAME?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设定一个spesific的versionNumber在摇篮自动生成APK文件名。

I'm trying to set a spesific versionnumber in the gradle autogenerated APK filename.

现在摇篮生成的myapp-release.apk ,但我希望它看起来像的myapp释放-1.0.apk

Now gradle generates myapp-release.apk but i want it to look something like myapp-release-1.0.apk.

我试图重新命名选项,多数民众赞成看起来凌乱。有一个简单的方法来做到这一点?

I have tried renaming options thats seems messy. Is there a simple way to do this?

buildTypes {
    release {
       signingConfig signingConfigs.release
       applicationVariants.each { variant ->
       def file = variant.outputFile
       variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" +    defaultConfig.versionName + ".apk"))
    }
}

我已经试过上面没有运气的code。有什么建议么? (用摇篮1.6)

I have tried the code above with no luck. Any suggestions? (using gradle 1.6)

推荐答案

这解决了我的问题:使用 applicationVariants.all 而不是 applicationVariants.each

This solved my problem: using applicationVariants.all instead of applicationVariants.each

buildTypes {
      release {
        signingConfig signingConfigs.release
        applicationVariants.all { variant ->
            def file = variant.outputFile
            variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk")) 
        }
    }       
}

更新:

如此看来,这并不与0.14+版本的Andr​​oid的工作室摇篮插件工作。

Update:

So it seems this does not work with 0.14+ versions of android studio gradle plugin.

该做的伎俩(参考此<一个href="http://stackoverflow.com/questions/27068505/how-do-i-add-a-version-number-to-my-apk-files-using-0-14-versions-of-the-androi?lq=1">question ):

This does the trick (Reference from this question ) :

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

这篇关于如何用摇篮的APK文件名设置VERSIONNAME?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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