https://kotlinlang.org logo
r

Rita Curado

07/10/2020, 9:22 AM
Hi everyone! Could someone tell me if it is possible to access properties from
gradle.properties
in common code? If not, how can I set an environment variable and read it on common code? Thanks in advance
k

Kamil Kalisz

07/10/2020, 11:39 AM
Hi Rita, Could you share your use case ? As i know gradle.properties are compile time available, and are not included into result binary. I don’t know your use case but probably it would be best for you to generate kotlin class in the common code that will contain configuration values from gradle.properties
a

andylamax

07/10/2020, 12:27 PM
This is what I am doing at the moment. By using gradle, I export a json file, that is bundle up in android, or, js, or jvm. From there I can read the variables from the json as my environment variables. I have defined expect actual methods for reading json into a Map<String,Any> which can be used in MPP
r

Rita Curado

07/10/2020, 1:27 PM
Thanks for the answers 🙂 So I should add a new file with the variables I need right?
Meanwhile I started using an external library called BuildKonfig that let me specify some variables from gradle.properties to be used inside common code
a

andylamax

07/10/2020, 2:16 PM
a link to BuildKonfig please?
r

Rita Curado

07/10/2020, 2:17 PM
3 Views