I have multiple applications but it is one application with many flavors for many domains.
For every app I have separate package with AppConfig file and res folder which contains images for every domain.
Paths: app/src/eu/java/in/AppConfig; app/src/com/java/in/AppConfig; app/src/fr/java/in/AppConfig and etc.
And separate productFlavors for every build. I'm making for every domain separate apk.
But now I need to make one app and app itself must on run time change configs and resources then user change it.
For example menu where user choose domain and app must take for all application correct configs.
How I can achieve this solution? How can i build one opp which change on runtime its resources and configurations.
//config example
object AppConfig {
const val oauthToken = "url"
const val oauthClientID = "id"
....
}
//build.gradle example
productFlavors {
dev {
applicationId "dev.in.app"
dimension "default"
}
eu {
applicationId "eu.in.app"
dimension "default"
}
....
}
To summarise, you currently have a multi-flavour app that requires a rebuild to change, and you instead want end users to be able to switch?
Unfortunately there's no "type this code and it'll work" solution, you're going to need to rearchitect your app. You're going to need to move away from Gradle variant switching to in-code variant switching. The overall approach will be something like:
/eu/java/...MyFile.kt
needs to become /java/.../eu/MyFile.kt
.isFeatureEnabled
, you need to ensure these checks pay attention to the currently selected variant instead of being fixed values.Using your AppConfig
example, you might have /Config/
directory with EuConfig
, UsConfig
etc defining those values. Then, a ConfigManager
class that lets the user change the active Config and look up which features are required. For resources (strings, colours) you have 2 solutions:
R.string.eu_title
instead of R.string.title
).Ultimately this is probably going to take a fair bit of work, and it's hard to answer in detail without more information on your exact setup. Luckily when I've performed similar migrations before the work isn't necessarily hard, just takes a bit of thought and lots of testing.
Edit: Just realised I answered a similar question 3 years ago, there's more helpful tips there!