How do I add a version number to my APK files using 0.14+ versions of the Android Gradle plugin?

后端 未结 3 2071
不知归路
不知归路 2021-01-11 15:49

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

There\'s an another answer that works with pre-0.14.x

3条回答
  •  时光取名叫无心
    2021-01-11 15:52

    When using version 3.0.0 of the plugin or higher, you have to make a slight change:

    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            outputFileName = "myapp-${variant.versionName}-${variant.name}.apk"
        }
    }
    

    The 3.0.0 plugin migration documentation says:

    If you use each() to iterate through the variant objects, you need to start using all(). That's because each() iterates through only the objects that already exist during configuration time- but those object don't exist at configuration time with the new model. However, all() adapts to the new model by picking up object as they are added during execution.

提交回复
热议问题