How to change app name per Gradle build type

前端 未结 10 874
慢半拍i
慢半拍i 2020-11-29 20:09

I am trying to figure out a way to be able to change my application\'s app name per build type in gradle.

For instance, I would like the debug version to have

10条回答
  •  佛祖请我去吃肉
    2020-11-29 20:38

    There are multiple ways you can do.

    you can create manifestPlaceholders OR resValue in app level build.gradle. e.g.

    buildTypes {
         release {
              ...
              manifestPlaceholders = [appLabel: "My App"]
              //resValue "string", "appLabel", '"My App"'
         }
         debug {
              ...
              manifestPlaceholders = [appLabel: "My App - Debug"]
              //resValue "string", "appLabel", '"My App - Debug"'
         }
    }
    

    OR

    If you have productFlavors, you can create there

    flavorDimensions "env"
    productFlavors {
        dev {
            dimension "env"
            ...
            manifestPlaceholders = [appLabel: "My App - Development"]
            //resValue "string", "appLabel", '"My App - Development"'
        }
        prod {
            dimension "env"
            ...
            manifestPlaceholders = [appLabel: "My Awesome App"]
            //resValue "string", "appLabel", '"My Awesome App"'
        }
    }
    

    Then in AndroidManifest.xml if you are using manifestPlaceholders, just change android:label="${appLabel}" as below OR if you are using resValue, just change android:label=@string/appLabel

     //OR `android:label=@string/appLabel`
        
        
    
            
                
    
                
            
        
    
    

    NOTE: Make sure to change android:lable as well in of LAUNCHER category. If it doesn't require to use android:label in , just remove this.


    If you do not want to add in build.gradle directly, you can add in values/string.xml of selected ProductFlavors. e.g.

    Add

    My App - Development 
    

    in app/src/dev/res/values/string.xml

    and

    My Awesome App 
    

    in app/src/prod/res/values/string.xml

提交回复
热议问题