app-release.apk how to change this default generated apk name
Yes we can change that but with some more attention
Now add this in your build.gradle in your project while make sure you have checked the build variant of your project like release or Debug
so here I have set my build variant as release
but you may select as Debug as well.
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig getSigningConfig()
applicationVariants.all { variant ->
variant.outputs.each { output ->
def date = new Date();
def formattedDate = date.format('yyyyMMddHHmmss')
output.outputFile = new File(output.outputFile.parent,
output.outputFile.name.replace("-release", "-" + formattedDate)
//for Debug use output.outputFile = new File(output.outputFile.parent,
// output.outputFile.name.replace("-debug", "-" + formattedDate)
)
}
}
}
}
You may Do it With different Approach Like this
defaultConfig {
applicationId "com.myapp.status"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
setProperty("archivesBaseName", "COMU-$versionName")
}
Using Set property method in build.gradle
and Don't forget to sync the gradle before running the projects
Hope It will solve your problem :)
A New approach to handle this added recently by google update
You may now rename your build according to flavor or Variant output
//Below source is from developer android documentation
For more details follow the above documentation link
Using the Variant API to manipulate variant outputs is broken with the new plugin. It still works for simple tasks, such as changing the APK name during build time, as shown below:
// 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.
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
Renaming .aab bundle
This is nicely answered by David Medenjak
tasks.whenTaskAdded { task ->
if (task.name.startsWith("bundle")) {
def renameTaskName = "rename${task.name.capitalize()}Aab"
def flavor = task.name.substring("bundle".length()).uncapitalize()
tasks.create(renameTaskName, Copy) {
def path = "${buildDir}/outputs/bundle/${flavor}/"
from(path)
include "app.aab"
destinationDir file("${buildDir}/outputs/renamedBundle/")
rename "app.aab", "${flavor}.aab"
}
task.finalizedBy(renameTaskName)
}
//@credit to David Medenjak for this block of code
}
Is there need of above code
What I have observed in the latest version of the android studio 3.3.1
The rename of .aab bundle is done by the previous code there don't require any task rename at all.
Hope it will help you guys. :)
“app-release.apk” how to change this default generated apk name that allows to install after?
Use below code and put it at outside of the android{ }
closure:
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
// Redirect your apks to new defined location to outputDirPath
def outputDirPath = new File("${project.rootDir.absolutePath}/apks/${variant.flavorName}/${variant.buildType.name}")
variant.packageApplicationProvider.get().outputDirectory = outputDirPath
def apkFileName = "${rootProject.name}_${android.defaultConfig.versionName}.apk"
output.outputFileName = apkFileName // directly assign the new name back to outputFileName
}
}
Your final apk name will be something like app_1.0.0.apk
, if you want to make the name be more fancy, you can modify below line per your requirement.
def apkFileName = "${rootProject.name}_${android.defaultConfig.versionName}.apk"
Android: How to change specific name of the generated apk file in Android Studio?
Step 1:
Go to root of the main project, under app , right click on app and refactor the app into specific name (example iPlanter) and press ok
Step 2:
Go to Project Setting file which is setting.gradle
file
setting.gradle
file contains
include ':app'
Now need to replace app by specific name.
For Example
app replace by iPlanter in include ':app'
it looks like below
include ':iPlanter'
then Sync project, after that run your application.
Finally, App generate an apk like iPlanter-debug.apk
or iPlanter-release.apk
file.
Change generated apk name from app-debug.apk
You can use applicationVariants and change the output file in the build.gradle. You can also modify the name regarding to your needs.
buildTypes{
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = file("$project.buildDir/apk/test.apk")
}
}
}
How to change apk name by using gradle like this format?
Update: Please check Anrimian's answer below which is much simpler and shorter.
Try this:
gradle.properties
applicationName = MyApp
build.gradle
android {
...
defaultConfig {
versionCode 111
...
}
buildTypes {
release {
...
applicationVariants.all { variant ->
renameAPK(variant, defaultConfig, 'R')
}
}
debug {
...
applicationVariants.all { variant ->
renameAPK(variant, defaultConfig, 'T')
}
}
}
}
def renameAPK(variant, defaultConfig, buildType) {
variant.outputs.each { output ->
def formattedDate = new Date().format('yyMMdd')
def file = output.packageApplication.outputFile
def fileName = applicationName + "_V" + defaultConfig.versionCode + "_" + formattedDate + "_" + buildType + ".apk"
output.packageApplication.outputFile = new File(file.parent, fileName)
}
}
Reference:
https://stackoverflow.com/a/30332234/206292
https://stackoverflow.com/a/27104634/206292
How to generate output APK file with Customised name in Android Studio?
1. For changing app bundle name (.aab file):
in app module's build.gradle:
def dateFormat = new Date().format('ddMMMyy_HHmm')
defaultConfig {
applicationId "com.xyz"
minSdk 21
targetSdk 31
versionCode 3
versionName "1.0.2"
setProperty("archivesBaseName", "yourappname" + "_v" + versionName + "(" + versionCode + ")_"+dateFormat)
}
For example: if your app name is XYZ then the bundle name will generated with name: XYZ_v1.0.2(3)_28Jan22_1152-prod-release
where,
yourappname is XYZ ,
versionName is 1.0.2 ,
versionCode is 3 ,
dateFormat is 28Jan22_1152 ,
and app flavorType and buildType is prod-release
2. For changing apk file name (.apk file)
in app module's build.gradle:
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
def name = "XYZ"
def SEP = "_"
def flavor = variant.productFlavors[0].name
def buildType = variant.buildType.name
def versionName = defaultConfig.versionName
def versionCode = defaultConfig.versionCode
def newApkName = name + SEP + "v" + versionName + SEP + flavor + SEP + buildType + SEP + "vc" + versionCode + SEP + dateFormat + ".apk"
output.outputFileName = newApkName
}
}
}
For example, if your app name is XYZ then this will generate APK file with following custom name:
XYZ_v1.0.2_prod_release_vc3_28Jan22_1152
Note: You can change dateFormat as per your requirement, for apk name if you don't have productFlavours then remove all related references from the code given above.
How to change the name of the apk file?
No, sadly you cannot control the file name in the config.xml, but the file name doesn't matter. In the config.xml, you specify the name of your app as it will appear to the users on their mobiles, and that's what matters.
If you like to give the file a specific name for your own file management (which is what I do too), you'll have to manually rename the file every time you create a new build.
Related Topics
How to Attach Image from Drawable to Gmail
Message "Error: Resource Android:Attr/Lstar Not Found"
Android Drawerlayout - No Drawer View Found with Gravity
Fragment Lifecycle: When "Ondestroy" and "Ondestroyview" Are Not Called
How to Play an Mp3 in the Res/Raw Folder of My Android App
Error Type 3: Activity Class {...} Does Not Exist
Kotlin and Firebase Read and Write Data
Applying Word Stemming in Searchview for Fetch Data from Firebase Database
Google Play App Description Formatting
What Are the Android Sdk Build-Tools, Platform-Tools and Tools? and Which Version Should Be Used
Android Opengl Es 2.0 Emulator
When a Fragment Is Replaced and Put in the Back Stack (Or Removed) Does It Stay in Memory
Google Analytics in Android App - Dealing with Multiple Activities