Change string resource by flavor / debug-build

前端 未结 5 1357
长情又很酷
长情又很酷 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:52

    Yes you can do that inside your app gradle under buildTypes..

     buildTypes {
            mybuild {
                     resValue "string", "test_some_card_text", '"test"'
                     resValue "string", "other_text", '"other"'
                    }
             debug {
                     resValue "string", "test_some_card_text", '"test"'
                     resValue "string", "other_text", '"other"'
                  }
              }
    

    Then access it like this.

    getApplicationContext().getResources().getString(R.string.test_some_card_text);
    getApplicationContext().getResources().getString(R.string.other_text);
    

    For build you need to select that build variants and have to build it.

提交回复
热议问题