곰돌푸우❤️

manifestPlaceholders

map 자료구조를 띄고 있으며 key: value 형식으로 변수를 선언할 수 있다.
ex) manifestPlaceholders = [key1: value1, key2: value2, …]

android {    
    defaultConfig {        
        manifestPlaceholders = [hostName:"www.example.com"]    
    }    
    ...
}

AndroidManifest.xml 파일 안에서 ${key}로 Gradle 빌드 변수값을 얻어올 수 있다.

<intent-filter ... >    
    <data android:scheme="http" android:host="${hostName}" ... />                   
    ...
</intent-filter>

 

applicationId

앱을 식별하기 위한 고유한 ID. 기기와 Google Play Store 등에서 이 값으로 앱을 식별한다. 프로젝트에서 보통 여러 빌드 변형을 사용하는데 이 때 applicationIdSuffix를 이용해 applicationId의 값을 com.example.myapp.free, com.example.myapp.pro 등으로 바꾸어 각각 다른 앱으로 식별하게 한다.

android {
    defaultConfig {        
        applicationId "com.example.myapp"    
    }    
    productFlavors {        
        free {            
            applicationIdSuffix ".free"        
        }        
        pro {            
            applicationIdSuffix ".pro"        
        }    
    }
    buildTypes {
        debug {            
            applicationIdSuffix ".debug"        
        }    
    }
}

 

AndroidManifest.xml에서 현재 빌드 변형의 applicationId를 참조하고 싶을 땐 아래와 같이 사용한다.

<intent-filter ... >    
    <action android:name="${applicationId}.TRANSMOGRIFY" />    
    ...
</intent-filter>

위와 같은 방식을 사용하면 각 빌드 변형에 AndroidManifest.xml을 따로 두지 않고 하나의 Manifest 파일에서 처리가능하다.

 

그럼 각 빌드변형에 따라 아래처럼 빌드가 된다.

free 빌드 변형으로 빌드 시

<intent-filter ... >    
    <action android:name="com.example.myapp.free.TRANSMOGRIFY" />    
    ...
</intent-filter>

pro 빌드 변형으로 빌드 시

<intent-filter ... >    
    <action android:name="com.example.myapp.pro.TRANSMOGRIFY" />    
    ...
</intent-filter>

free 빌드 변형, debug 타입으로 빌드 시

<intent-filter ... >    
    <action android:name="com.example.myapp.free.debug.TRANSMOGRIFY" />    
    ...
</intent-filter>

 

공식 문서

https://developer.android.com/studio/build/manifest-build-variables

반응형
facebook twitter googleplus kakaostory naver