nikib3ro
nikib3ro

Reputation: 20596

Generate APK with declared name in Gradle without any suffixes

I know that it is possible to specify APK name by using following command in Gradle build file:

setProperty("archivesBaseName", "something")

There are lots of questions here that deal with this. But doing this also results in APK that has flavor and build variant appended to the name. So using above command results in APK that's named something-dev-debug.apk.

Is there a way to completely specify file name without appending any suffixes. I already have appId in my flavors like this:

//...
productFlavors {
    dev {
        applicationId "com.myapp.dev"
        setProperty("archivesBaseName", applicationId)
    }
//...

So ideally I would like to produce APK named com.myapp.dev.apk without any extra suffixes or version numbers. Is this possible?

Upvotes: 2

Views: 198

Answers (1)

nikib3ro
nikib3ro

Reputation: 20596

It seems that this shouldn't be done with setPropery. Rather you can define handler that changes output file name as final step by adding following code to the end of android { } section in gradle file:

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def file = output.outputFile
        def appId = variant.applicationId
        def fileName = appId +".apk"
        output.outputFile = new File(file.parent, fileName)
    }
}

Upvotes: 1

Related Questions