Development issue/problem:

I configure the MOT file name of my Android application in the build.gradle script as follows:

android {
defaultConfig {
project.ext.set(archivesBaseName, MyApplication);
}
}

Now, if I use the flavorings in the products:

android {
productFlavors {
green {
applicationId com.example.myapplication.green
}

blue {
applicationId com.example.myapplication.blue
}
}
}

Is it possible to change the name of each MOT? I have experimented without success with archiveBaseName and baseName. Finally, I’d like to get the following files:

build/outputs/apk/blue-debug-1.2.1.apk
build/outputs/apk/blue-release-unbound.apk
build/outputs/apk/blue-release-unbound1.2.1.apk
build/outputs/apk/blue-release-unbound.apk
build/outputs/apk/green-debugger-1.2.1.apk
build/outputs/apk/green-debugger-unbound.apk
build/outputs/apk/green-release-1.2.1.apk
build/outputs/apk/green-release-unbound.apk

How can I solve this problem?

Solution 1:

Try including it in your build.gradle android lock.

buildType {debug {// debug buildType-specific stuff} release{/ release buildType-specific stuff}applicationVariants.all { variant ->as (variant.buildType.name.equals(release) &&variant.productFlavors[0].name.equals(green) &&variant.zipAlign) {def apk = variant.outputFile;variant.outputFile = new file (apk.parentFile, green.apk);} anders if(variant.buildType.name.equals(release) &&variant.productFlavors[0].name.equals(blue) &&variant.zipAlign) {def apk = variant.outputFile;variant.outputFile = new File(apk.parentFile, blue.apk);}}}}.

The outputs should now be green.apk and blue.apk.

Solution 2:

For Android Studio 3.0 you need to switch from one to the other:

applicationVariants.all { variant ->
variant.outputs.each { output ->
outputFile = new file(outputFile.parent, whatever + .apk)
}
}

On:

android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = whatever + .apk)
}
}

Solution 3:

For Android Gradle Plugin 0.13.+ you must use something similar:

android{buildTypes {applicationVariants.all { variant ->variant.outputs.each { output ->def apk = output.outputFile;def newName = mysms- + variant.baseName.replace(-release, ) + – + defaultConfig.versionName + .apk;output.outputFile = new File(apk.parentFile, newName);}}}}}

Solution 4:

This will help you in 2021.

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 OF com.examplePaid.appdef version_name = variant.versionNamedef versionCode = variant.versionCode // for example 1.0def flavorName = variant.flavorName // for example 1.0def flavorName = variant.flavorName // for example Free
def buildType = variant.buildType.name // for example debug
def variantName = variant.name // for example FreeDebug

// Configure the name of the application using variables
outputFileName = ${variantName}.apk
}
} }.

Name Apk FreeDebug.apk

Proof
Fill in the description of the image here

Give here a description of the image

Solution No 5:

I did it this way:

productsTests {
production {
applicationId com.example.production
}

staging {
applicationId com.example.production.staging

}

applicationVariants.all { variant ->
variant.outputs.each { output ->
if(variant.productFlavors[0].name.equals(staging)){
outputFile.outputFile.new File(outputFile.parent,
outputFile.name.replace.app-staging-release, test)) ;

}else{
outputFile.outputFile.parent.new File.outputFile.parent.
outputFile.name.replace.app-production-release, production);
}

}
}
}

Solution No 6:

It’s strange that you need it, because the default MOT file name is already different.

If you look at line 1346 here, you can see that the output file uses variantData.variantConfiguration.baseName.

variantData.outputFile = project.file($project.buildDir/apk/${project.archivesBaseName}-${variantData.variantConfiguration.baseName}.apk)

And the documentation for baseName

/**
* Full and unique name of the variant, including BuildType, Flavors and Test, with hyphens separated.
* (similar to full name, but with a hyphen)
*/
private String mBaseName ;

So if you run gradle assembleFreeDebug, you should get the file ProjectName-free-debug.apk.

However, if this is not the case, or if you want a different filename, you can use the following code to modify it.

android {
buildTypes {
debug {}
alpha {}
release {}
}
productAroma {
free {}
paid {}
}
applicationVariants.all { variant ->
def newApkName = variant.name + my-custom-addition + .apk;
variant.outputFile = new File(${{project.buildDir}/outputs/apk/, newApkName);
}
}

Solution No 7:

It works for me:

Add variant.productFlavors[0].name to the name APK.

Example code :

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’
applicationVariants.alle { variant ->
variant.outputs.each { variant ->
output.outputFile = new file (output.outputFile.parent, APPNAME_ + variant.productFlavors[0].name + _ + variant.versionName + .apk)

}
}
}
}

Solution No 8:

Here is my (heh) version of Lakshman’s answer above, I’m not sure why I need variants.outputs.each, but I do.

defaultConfig [applicationId my.company.comminSdkVersion 16targetSdkVersion 25applicationVariants.all [variant ->if (variant.productFlavors[0].name.equals(VariantA))] {variant.outputs.each { output ->def apk = output.outputFile ;output.outputFile = new file(apk.parentFile, Blue.apk);}}other { // Only two variants variant.outputs.each { output ->def apk = output.outputFile;outputFile = new file(apk.parentFile, Green.apk);}}}}}.

Solution No 9:

That’s what you need.

android {
defaultMatching {
……

// custom output apk name applicationVariants.all {variant ->variant.outputs.all {outputFileName = ${variant.productFlavors[0].name}-${variant.buildType.name}-${variant.versionName}.apk}}……}

Solution No 10:

Every answer here is identical and outdated. Easy to make [taste]-[version]-[type of construction]:

android {
productFlavors {
green {
applicationId com.example.myapplication.green
setProperty(archivesBaseName, Green- + defaultConfig.versionName)
}

blue {
applicationId com.example.myapplication.blue
setProperty(archivesBaseName, Blue- + defaultConfig.versionName)
}
}
}

If your name is version 1.2.1, the gradle assembly will work:

Green-1.2.1-debugging.apk

Green-1.2.1-Release.apk

Blue-1.2.1- UPP Troubleshooting

Blue-1.2.1-Release.apk

Good luck!

android build variants vs flavors,select build variant greyed out,applicationidsuffix,matchingfallbacks,buildconfigfield,android get build flavor programmatically,archivesbasename,android gradle rename aab,android archivesbasename,rename app bundle,android change aab file name,gradle rename app bundle,gradle build command java,gradle build apk command line,gradle commands cheat sheet,material design for android developers,gradle build command skip test,where is build.gradle file in android studio,android studio app-debug.apk change name,how to change apk name in android studio,android gradle rename apk,gradle outputfile,android flavors,flavordimensions,android flavor dependencies,android studio build for x86,gradle buildconfig,apk builds

You May Also Like

Megadede APK Download For Android

The Megadede APK Download For Android is a puzzle game that you…

enable Annotation Processors option in Android Studio 2.2 –

Development issue/problem: I am trying to use Java 8 in my project…

Download Periscope For PC/Laptop on Windows(10/8.1/8/7) & Mac

If you want to download and install the Periscope app on Windows…

How to install Samsung Galaxy drivers for Windows 10

Some time ago, we published an article about how to install your…