android app / business-logic config [英] android app/business-logic config

查看:251
本文介绍了android app / business-logic config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用开发商如何在Android应用中存储特定于应用的(即我的服务器地址,路径端点等)全局和构建变量特定配置值?另外,是否可以覆盖?即。我想在我的global.config中设置一个默认值,但是在staging-build-variant.config和prod-build-variant.config中的碰撞应该重写这个,而dev-build-variant.config只是使用默认值。

how does an app developer store app-specific (ie. my server addresses, path endpoints, etc.) global and build variant specific config values in an android app? further, is it possible to have overrides? ie. i want to set a default value in my global.config, but collisions in staging-build-variant.config and prod-build-variant.config should override this, while dev-build-variant.config would simply use the default value.

我已经阅读过SharedPreferences,但这似乎是在运行时存储用户输入以供以后运行,我已经阅读关于人们使用类来保存常量,但是不太适合,因为我没有得到任何好处的具体配置值覆盖常见的。

i've read about SharedPreferences but this seems for storing user input at runtime for later runs, and i've read about people using a class to hold constants, but that doesn't quite fit either as i don't get any benefit of a specific configuration values overriding common ones. there is also a lot of seemingly outdated articles out there which i'm not sure are accurate anymore.

我问这是一个注释在这个问题,这似乎接近我在寻找,但我认为我会问一个问题更多的曝光。

i asked this as a comment in this question which seems to be close to what i'm looking for, but thought i'd ask as a question for more exposure.

编辑:也许我解释这不好 - 要澄清,

maybe i explained this poorly - to clarify, this comment.

推荐答案

Justin,看起来是什么whant是一个图书馆项目。您必须使用一个默认配置创建库项目。
假设项目名为Core,然后它具有以下strings.xml:

Justin, it seems that what you whant is a library project. You will have to create a library project with one default configuration. Let's say that project is called Core and then it has the following strings.xml:

<string name="server_address">htt://path.to.server</string>

这样,您可以为项目创建一个模块(称为 app1 )使用核心库项目。然后,您将以两个 strings.xml文件结束。
因此,应用程序模块中的strings.xml文件将覆盖库项目中的strings.xml。然后您可以:

This way you can create a module (called app1) for the project that uses the 'Core' library project. Then you will end with two strings.xml file. So the strings.xml file from your app module will override the strings.xml from the library project. Then you can have:

<string name="server_address">htt://app1.path.to.server</string>

资源:
创建库项目

[ UPDATED ]

而不是使用库,你可以尝试一个成绩变量。请参阅以下问题:
Gradle变量
此链接关于构建变体:
构建变体

Instead of use a library you can try a grade variable. See this question: Gradle Variables And this link about build variants: Build variants

这篇关于android app / business-logic config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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