安卓版本和测试模式? [英] Android: Release and testing mode?
问题描述
我工作的Android项目,我想设置一些变量上运行的时候,该怎么办呢?
I'm working on android project and I want to set some variable on running time, how to do it ?
更具体的我想有两个运行的配置:
to be more specific I want to have two running configuration:
- pre的生产配置:在这里我用一个URL进行测试(字符串为例URL = staging.domain.net)
- 产品配置:在这里我使用其他网址(URL为例= api.domain.net)
不过,我觉得关于使用蚂蚁,但我不知道怎么办!
I though about using ant but I have no idea how !
编辑1:
我的应用程序访问的远程服务器和服务,使用测试网址,有时我想用生产URL,而不是测试网址。那么,可能有两个运行的配置设置?
My application accesses remote servers and services, using a test URL, sometime I want to use the production URL and not test url. So is possible to have two running configuration setting ?
推荐答案
您可以在code定义URL和决定取决于 BuildConfig.DEBUG $ C $要使用哪一个C>。
You can define both URLs in your code and decide which one to use depending on BuildConfig.DEBUG
.
另外,如果你不想在你的$ C $来定义它们c您可以使用一个属性( setprop支撑值
),然后在你的应用检索( getprop托
)。
Alternatively, if you don't want to define them in your code you can use a property (setprop prop value
) and then retrieve it in your app (getprop prop
).
如果您使用的是仿真器甚至还有一个-prop选项
If you are using the emulator there's even a -prop option
-prop <name>=<value> set system property on boot
这篇关于安卓版本和测试模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!