Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming Android app Bundle and APK (.aab and .apk) files with app name, version and build type - build.gradle.kts

How To change Android App Bundle/APK name (app.aab/app.apk) to reflect App version, App name and build type in build.gradle.kts

Here is the build.gradle.kts, I need to rename apk/aab here

android {
namespace = "com.example.app"
compileSdk = 34

val prop = Properties().apply {
    load(FileInputStream(File(rootProject.rootDir, "keystore.properties")))
}

signingConfigs {
    create("my_sign") {
        storeFile = file(prop.getProperty("storeFile"))
        storePassword = prop.getProperty("storePassword").toString()
        keyPassword = prop.getProperty("keyPassword").toString()
        keyAlias = prop.getProperty("keyAlias").toString()
    }
}

defaultConfig {
    applicationId = "com.example.app"
    minSdk = 24
    targetSdk = 34
    versionCode = 1
    versionName = "1.0.0"

    testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    vectorDrawables {
        useSupportLibrary = true
    }
    signingConfig = signingConfigs.getByName("my_sign")
}

buildTypes {

    release {
        isMinifyEnabled = true
        isShrinkResources = true
        proguardFiles(
            getDefaultProguardFile("proguard-android-optimize.txt"),
            "proguard-rules.pro"
        )
    }
    debug {
        isMinifyEnabled = false
        isShrinkResources = false
    }
}

I would be grateful for any code snippet, suggestions, references, or links.

like image 780
Alfin Avatar asked Sep 03 '25 17:09

Alfin


1 Answers

After migration to Kotlin 2.0.0 (and Gradle 8.7) I faced with this problem - how to rename output files (both APK & AAB) and make it short. The answer of @bqliang is nice, but too long to me.

And here is the recipe:

android {
  defaultConfig {
    setProperty("archivesBaseName", "${applicationId}-${versionName)-${versionCode}")
  }
}

It renames everything like a charm! Tested in Android Studio Koala.

like image 121
Ilia Petukhov Avatar answered Sep 05 '25 06:09

Ilia Petukhov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!