Android的 - 开发和生产Web服务之间切换 [英] Android - switching between Development and Production Web Services

查看:107
本文介绍了Android的 - 开发和生产Web服务之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拥有的开发和生产Web服务之间我的应用程序切换而无需在code更改太多(和相对傻瓜证明)。

I want to have my app switch between development and production web services without changing too much in the code (and be relatively fool proof).

现在,我有我的web服务的地址为在确实在应用程序的其余部分的实际HTTP调用和开关code类的静态最后弦乐变量通过使用静态最终布尔

Right now I have my web service addresses as static final String variables in the class that does the actual HTTP calls and switch code in the rest of the app by using a static final boolean.

现在,而布尔是pretty方便,我不能用它来更改Web服务地址,因为它们本身就是静最后变量。什么是最好的做法为解决此?

Now whereas the boolean is pretty convenient, I can't use it to change the web service addresses because they are themselves static final variables. What is the best practice for tackling this ?

我发现,这样直接一些讨论倾向于使用Android SDK中提供的调试变量,但虽然它可以代替布尔,它没有解决另一个问题。

I found some discussions on SO that directed towards using Android SDK provided debug variable but although it can replace the boolean, it doesn't solve the other problem.

请注意:如果你想知道,我使用的Web服务类静态,所以我没有一个构造函数中,我可以检查调试变量改变的变量,加上我还希望他们能够静态最后

NOTE: In case you are wondering, I'm using the web services class statically so I don't have a constructor in which I can check the debug variable and change variables, plus I'd also like them to be static final.

推荐答案

我答应我会做到这一点,那就是:

I promised I'd do it and here it is:

http://blog.blundell-apps.com/switching-android-configurations-using-constants-and-ant/
http://blog.blundell-apps.com/running-一个蚂蚁脚本与 - 日食/

也反映在GitHub上: https://github.com/blundell/BuildChoiceTut

Also mirrored on GitHub: https://github.com/blundell/BuildChoiceTut

使用您可以使用Ant构建脚本交换机配置教程。

With the tutorial you can switch configurations using Ant build scripts.

您设置一个名为/配置/这里您持有不同的配置你的所有常量。一旦为每个文件即live.props dev.props beta.props

You setup a directory called /config/ in here you hold all your constants for different configurations. Once for each file i.e. live.props dev.props beta.props

则Ant运行时,它会读取所选的文件和'注入'他们到构建它被编译之前。

Then when Ant runs it will read the selected file and 'inject' them into your build just before it is compiled.

享受!

这篇关于Android的 - 开发和生产Web服务之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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