DoubtAN
DoubtAN

Reputation: 25

Rename archive Name for app with Build Variant in Android Studio 3.5

I was building single code for multiple apk's by using below gradle code:

flavorDimensions "version"

    productFlavors {
        Free {
            dimension "version"
            applicationId "com.exampleFree.app"
        }
        Paid {
            dimension "version"
            applicationId "com.examplePaid.app"
        }
    }

Now when i build, it creates archive app as below name:

app-Free-debug.apk

When I include below code in gradle,

setProperty("archivesBaseName","")

It now creates as below APK archive name

-Free-debug.apk

I need my APK file name as below

Free-debug.apk

I was so close but how to remove that hypen (-) which is append in prefix ?

Upvotes: 1

Views: 1729

Answers (1)

Happy Singh
Happy Singh

Reputation: 1482

Here you can use android migration like this.

android {

//........
flavorDimensions "version"
productFlavors {
    Free {
        dimension "version"
        applicationId "com.exampleFree.app"
    }
    Paid {
        dimension "version"
        applicationId "com.examplePaid.app"
    }
}

applicationVariants.all { variant ->
    variant.outputs.all { output ->
        def appId = variant.applicationId// com.exampleFree.app OR com.examplePaid.app
        def versionName = variant.versionName
        def versionCode = variant.versionCode // e.g 1.0
        def flavorName = variant.flavorName // e. g. Free
        def buildType = variant.buildType.name // e. g. debug
        def variantName = variant.name // e. g. FreeDebug

        //customize your app name by using variables
        outputFileName = "${variantName}.apk"
    }
}}

Apk name FreeDebug.apk

Proof enter image description here

enter image description here

Upvotes: 5

Related Questions