Android为发布版和调试版构建了单独的字符串值 [英] Android separate string values for release and debug builds

查看:215
本文介绍了Android为发布版和调试版构建了单独的字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我发布我的应用程序时,我都会将所有 url字符串和一些从测试更改为生产。我这样做的方式只是在我发布之前注释掉测试字符串。有没有更好的办法基础上,构建类型处理字符串?


解决方案

假设你使用Android Studio中,默认情况下,系统会创建一个基本的版本调试 flavor。因此,如果您在 app / src debug 版本文件夹

所以你的结构应该是这样的:

 项目
-app
-src
-debug
-java
...
$ -res b $ b - 值
-strings.xml
- 释放
-java
...
-res
- 值
-strings .XML
-main
-java
...
-res
- 值
-strings.xml

我还应该补充一点,如果你有一个字符串在 debug 发布文件夹,它将回退到您的主要文件夹。


Every time i release my app i change all my url strings and some keys from testing to production. The way I do it is just comment out the testing strings before i release. Is there a better way to handle strings based on the build type ?

解决方案

Assuming you use Android Studio, by default the system creates a basic release and debug flavor. So if you add a debug and release folder in the app/src folder of your project you can declare separate values there.

So your structure should be like this:

project
  -app
    -src
      -debug
        -java
          ...
        -res
          -values
            -strings.xml
      -release
        -java
          ...
        -res
          -values
            -strings.xml
      -main
        -java
          ...
        -res
          -values
            -strings.xml

I should also add that if you have a string which isn't defined in either of the debug or the release folder that it will fallback to your main folder.

这篇关于Android为发布版和调试版构建了单独的字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆