Reputation: 12940
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:
For production:
<api>api.example.com</api>
For development:
<api>dev.example.com</api>
I keep this config file under /assets/app-config.xml
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.
Upvotes: 2
Views: 859
Reputation: 5697
Customize your build using ANT
Please refer the following link for more information http://playaprogrammer.blogspot.com/2013/01/android-build-configuration-tutorial.html
I use this to create test and production builds from single source. You can have different configurations for development, QA, Production...
Upvotes: 0
Reputation: 14165
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>
When extracting the resource:
getString(BuildConfig.DEBUG ? R.string.url_api_dev : R.string.url_api);
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
.
If you use this method, it is a good idea to be aware of this bug.
Upvotes: 4