How to access variant.outputFileName in Kotlin

后端 未结 3 1867
抹茶落季
抹茶落季 2021-01-01 19:28

We\'ve been using a snippet like this one to rename the APK file generated by our Gradle build:

android.applicationVariants.all { variant ->
    variant.o         


        
3条回答
  •  无人及你
    2021-01-01 20:32

    Shorter version using lambdas:

        applicationVariants.all{
            outputs.all {
                if(name.contains("release"))
                    (this as BaseVariantOutputImpl).outputFileName = "../../apk/$name-$versionName.apk"
            }
        }
    

    This will place APK into app/apk folder with name made of variant name and version code.
    You can change the format of filename as you wish.
    Important: it must be done only on release builds, because ".." in path corrupts debug build process with strange errors.

提交回复
热议问题