Change string resource by flavor / debug-build

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

    Yes, Gradle lets you override strings.

    • Add this inside buildTypes{} in your app/build.gradle

      debug { applicationIdSuffix "debug" }

    • That should create a directory titled debug next to main. If not then manually create one. (Seriously, I haven't tried this, but I know this is possible.)

    • Then if your strings_test.xml is under res/values, create similar directory structure under debug/ and put your strings_text.xml with debug specific strings there. This will show up in your debug build. The ones under release/main/res/values will show up in your release build.

    PS: You can override all res and asset data like this according to buildTypes and flavor. You can't override Java files though, you could however add them.

提交回复
热议问题