Using a different manifestPlaceholder for each Build Variant

前端 未结 6 504
长发绾君心
长发绾君心 2020-12-09 03:01

I will start by saying that I am very new to Gradle, so I apologize if this has already been answered.

I\'m working on an Android application that uses an API key to

6条回答
  •  有刺的猬
    2020-12-09 03:31

    Similarly to the accepted answer, you could do it with string resources, if you didn't want to duplicate your manifests.

    For example, if you had two flavors (flavor1 and flavor2) You'd end up w/ the following source sets.

    app/
      src/
        main/
          res/
             values/strings.xml
        flavor1Release/
          res/
             values/strings.xml
        flavor1Debug/
          res/
             values/strings.xml
    
        flavor2Release/
           res/
             values/strings.xml
        flavor2Debug/
           res/
             values/strings.xml
    

    You could then just use a string resource for your key value

    
        
            
            
            
    
    

    One further optimization to keep all your keys in one place is to define them all in strings.xml in your main source set. and then have the flavor/build source sets reference those.

    for example:

    
        flavor1ReleaseKey
        flavor1DebugKey
        flavor2ReleaseKey
        flavor2DebugKey
    
    

    then in each of your flavor/build sourceSets, you just reference those keys.

    flavor1Release/res/values/strings.xml

    
         @string/flavor1ReleaseKey
    
    

提交回复
热议问题