본문 바로가기
IT/배포

Android Studio 빌드 파일명 변경 (APK, AAB)

by TechTonic 2022. 6. 24.
반응형

앱 배포를 위해 Android Studio 에서 APK/AAB 파일을 추출할때 파일명이 'app-release' 으로 추출된다.

버전 관리를 위해 추출 시 빌드 정보를 포함한 파일로 나오도록 변경해보자.

 

1. Android Studio 파일명 변경을 위한 Gradle 수정

build.gradle (Module)

android {
    compileSdkVersion 31
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "********"
        minSdkVersion 26
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"

        applicationVariants.all { variant ->
            variant.outputs.all { output->
                def apk = output.outputFile;
                def packageName = defaultConfig.applicationId
                def versionName = defaultConfig.versionName
                def dateStr = new Date().format("yyyyMMdd")
                def newName
                if (apk != null && apk.name.startsWith('app-release')) {
                    newName = apk.name.replace("app-release", dateStr + "_" + packageName + "_" + versionName);
                }else{
                    newName = apk.name.replace("app-debug", dateStr + "_" + packageName + "_" + versionName);
                }
                outputFileName = newName
            }
        }
    }

applicationVariants.all 항목의 내용을 COPY!!!!

 

자세한 내용은 Google Developer (build) 에서 확인할 수 있습니다.

 

2. Android Studio 파일명 변경 확인

위 코드로 추출 시 날짜, 패키지명, 버전의 조합으로 파일명이 생성된다.

예시) 20220624_com.test.test_1.0.apk

defaultConfig alias에서 수정하면 release, debug 두 타입 모두 변경 할 수 있다.

반응형

댓글