Android:发布和测试模式?

编程入门 行业动态 更新时间:2024-10-12 12:31:49
本文介绍了Android:发布和测试模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-20 09:10:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/980052.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   测试   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!