Change string resource by flavor / debug-build

前端 未结 5 1317
长情又很酷
长情又很酷 2021-02-08 21:26

Let\'s say we have strings_test.xml, which stores string values for testing and should be shown in a debug-release. When the apk gets build as a release version all values shoul

5条回答
  •  有刺的猬
    2021-02-08 21:58

    For those who come here looking for some way to apply a similar method to raw resources, I dealt with it using buildConfigField.

    gradle
    ...
    buildTypes {
        debug {
            ...
    
            buildConfigField "int", "shared_resource_name", 'R.raw.debug_resource_name'
    
            ...
        }
        prod {
            ...
    
            buildConfigField "int", "shared_resource_name", 'R.raw.prod_resource_name'
    
            ...
        }
    }
    

    Pay attention to the quotes. After that, place BuildConfig.shared_resource_name in the files wherever R.raw.resource_value used to be accessed directly.

    This can be used to other resources I think.

提交回复
热议问题