调试与Android的Eclipse的交换和发布的XML文件 [英] Android Eclipse Switching between debug and release for XML file

查看:100
本文介绍了调试与Android的Eclipse的交换和发布的XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些配置数据为我的Andr​​oid应用程序的XML文件。在它存在着可用于开发和生产的配置信息。例如。链接到我们的API可以如下设置:

I have an XML file that contains some config data for my Android App. In it there is config info that can be used for development and production. E.g. the link to our api can be set as follows:

有关生产:

<api>api.example.com</api>

有关发展:

<api>dev.example.com</api>

我不断/assets/app-config.xml

I keep this config file under /assets/app-config.xml

这是一个相当麻烦不断不必记住我的XML其中的设置。有没有一种方法来自动配置Eclipse / Android的,以便它使用的生产运行系统(出口等)的发展在调试模式。

It is quite a hassle to keep having to remember which setting I have in the XML. Is there a way to automatically configure eclipse/ android so that it uses the production for runtime (export etc.) and the development when in debug mode.

推荐答案

定义多种资源,并使用 BuildConfig.DEBUG 来有条件地获取资源或其他:

Define multiple resources and use BuildConfig.DEBUG to conditionally get a resource or another:

<string name="url_api">api.example.com</string>
<string name="url_api_dev">dev.example.com</string>

在提取资源:

getString(BuildConfig.DEBUG ? R.string.url_api_dev : R.string.url_api);

此常数设置为只要你从Eclipse中运行。当您选择的导出签名的应用程序包的选项,它将被设置为

This constant is set to true as long as you run from Eclipse. When you select the Export Signed Application Package option, it will be set to false.

如果您使用此方法,这是需要注意的的这个bug

If you use this method, it is a good idea to be aware of this bug.

这篇关于调试与Android的Eclipse的交换和发布的XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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