[Android] AGP 8.8.0에서 앱 이름 변경하여 빌드하기

AGP 버전이 올라감에 따라, 기존에 사용하던 방식으로는 더 이상 앱 이름이 변경 되지 않아 아래와 같이 로직을 수정해 주었다.
ex) app-release.apk -> appName_version.apk

aab의 경우, 태스크를 확인해 변경해주는 방식을 이용하였다.

androidComponents {
    onVariants { variant ->
        val versionName = android.defaultConfig.versionName
        variant.outputs.forEach { output ->
            if (output is com.android.build.api.variant.impl.VariantOutputImpl) {
                output.outputFileName = "${원하는 앱 이름}_${versionName}.apk"
            }
        }

        tasks.configureEach {
            if (name == "bundle${variant.name.capitalize()}") {
                doLast {
                    val aabDir = file("${buildDir}/outputs/bundle/${variant.name}/")
                    val aabFile = aabDir.listFiles()?.find { it.extension == "aab" }

                    if (aabFile != null) {
                        val newAabFile = File(aabDir, "${원하는 앱 이름}_${versionName}.aab")
                        aabFile.renameTo(newAabFile)
                        println("✅ AAB renamed to: ${newAabFile.name}")
                    } else {
                        println("⚠️ No AAB file found in ${aabDir.path}")
                    }
                }
            }
        }
    }
}

aab와 apk 모두 이름이 잘 변경되어 빌드 되는 것을 확인 할 수 있었다!

Leave a Comment