问题描述
限时送ChatGPT账号..我正在开发 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:
预生产配置:我使用 url 进行测试(例如 String url = staging.domain)生产配置:我使用其他 url(例如 url = api.domain)我虽然想使用 ant 但我不知道如何使用!
I though about using ant but I have no idea how !
编辑 1:
我的应用程序使用测试 URL 访问远程服务器和服务,有时我想使用生产 URL 而不是测试 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 ?
推荐答案
您可以在代码中定义这两个 URL,并根据 BuildConfig.DEBUG
决定使用哪一个.
You can define both URLs in your code and decide which one to use depending on BuildConfig.DEBUG
.
或者,如果您不想在代码中定义它们,您可以使用一个属性(setprop prop value
),然后在您的应用程序中检索它(getprop prop
>).
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
这篇关于Android:发布和测试模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论