[Android]Flavor

한 강·2022년 3월 2일
0

안드로이드

목록 보기
6/6

Flavor

  • 하나의 앱을 여러가지 버전으로 만들 수 있음
    • 실서버와 데브를 나눈다거나
    • 유료 앱과 무료 앱으로 나눈다거나
    • 광고가 있는 앱, 광고가 없는 앱으로 나눈다거나
  • build.gradle (:app) 에서 진행
  • 예시)
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }

    productFlavors {
        dev {
            dimension "flavors"
            applicationId "bible_real"
            applicationIdSuffix ".dev"
            versionCode 1
            versionName "1.0.0"
            buildConfigField "String", "url_base", "\"www.naver.com\""
            manifestPlaceholders = [appLabel: "bible_real"]
        }
        ope {
            dimension "flavors"
            applicationIdSuffix ".ope"
            applicationId "bible_dev"
            versionCode 1
            versionName "1.0.0"
            buildConfigField "String", "url_base", "\"www.naver.com\""
            manifestPlaceholders = [appLabel: "bible_dev"]
        }
    }

}

applicationVariants.all {
        variant -> variant.outputs.all {
            def name = applicationId
            def buildType = variant.buildType.name
            def versionName = variant.versionName
            outputFileName = "${name}-${buildType}-${versionName}.apk" }
    }
    flavorDimensions "flavors"
  • flavorDimension

    • 빌드의 구분을 나타냄
    • ex ) “api”, “mode”, “version” 등 api 버전에 따른 구분, 앱의 기능에 따라 구분 한다
  • manifestPlaceholders

    • AndroidManifest.xml 파일에서 ${appLabel} 처럼 사용 가능
  • applicationIdSuffix

    • defaultConfig 에 명시된 applicationId 뒤에 붙ㄴ느다
    • 각각의 version 의 ApplicationId 를 구분하게 해준다
  • buildConfigField

    • BuildConfig 클래스에서 호출 할 수 있는 값
    • BuildConfig.##### 으로 사용
  • crunchPngs

    • 압축되지 않은 png 리소스를 줄인다. ( 릴리즈는 기본 true , 빌드시간 증가 )
  • Manifest 도 변경 필요

  • 애플리케이션 속성과 MainActivity 속성도 변경 해야 함.

android:label="${appLabel}"
tools:replace="android:label"
  • Build Variants 를 통해 버전 변경 가능
profile
안드로이드 개발자 & Flutter 개발자

0개의 댓글