Hi all, i have a question. Lets say you have a pro...
# multiplatform
m
Hi all, i have a question. Lets say you have a prod, dev and local environment for an app + backend. I would like to be able to switch which environment next to the play icon. However, this is impossible because the gradle task to run the android app is not accepting environment variables for me to check in build.gradle. How have other people managed a one click reliable change in environment.
not kotlin but kotlin colored 4
h
Create a android product flavor and use Gradle to set the environment variables for your backend run tasks and wire them to the android run task.
d
It’s an issue I asked people as well I needed to be able to connect the mobile app either to the local environment or production via environment variables. I want to be able to know at runtime which environment is used to run the app, let’s say you have a .env file in the project and you want your apps to read this file and extract the env flag to check which host to use on the clients, but it’s not easily possible, android, ios and desktop have different file systems, did not find any existing libraries to do so I just have a Config.kt file in the shared module where I change the environment
m
That would mean backend starts the app, seems unnecessary. i want backend to run continuously whenever i want it to. And start the app whenever i want to with whatever flavor i want to. I would have to create a custom gradle task that builds the app with appropriate envs, would debugging even work?
@Dumitru Preguza I like that, problem is that the apk would contain the dev url that is potentially less secure.
But it is not possible to change the appId / bundle id in runtime which makes the solution not fit for me.
d
I don’t have at the moment dev and test environments, just local and prod for my pet project There are libs that can read the environment variables on multiplatform, but they can’t read the .env file, maybe gradle can set env vars for all targets and it might work
m
It works for gradle to read an .env file. but i would like to just be able to swtich version next to the play icon. One thing i have tried is adding a gradle task before it to update a gradle.properties file to change the flavor. this is unreliable (because of a bug in BuildKonfig) and requires a gradle sync for each swtich.