https://kotlinlang.org logo
#android
Title
# android
j

Joey

03/15/2020, 10:54 PM
Hi i am new in mobile development. I would like to ask if there is something like .env in android development? Thanks
m

Michael Bernier

03/15/2020, 11:24 PM
I don't know what is a .env, can you explain what you are looking to achieve ?
☝️ 1
j

Joey

03/16/2020, 3:35 AM
.env in web development is where the sensitive keys are stored like private API keys, credentials, etc. @Michael Bernier
a

Asad Ali

03/16/2020, 6:07 AM
You can consider gradle(app level file) where you can setup different enviroments i.e qa,prod and there is gradle.properties where you can stores different strings (server url, any key) and use them while creating different environments.
j

Joey

03/16/2020, 6:45 AM
Thank you so much @Asad Ali. Will look into this
🤗 2
c

Colton Idle

03/17/2020, 1:44 PM
You can also just create straight up environment variables.
s

stantronic

03/17/2020, 1:51 PM
What we do is have local.properties added to the BuildConfig object -
Copy code
android {
    compileSdkVersion 29
    buildToolsVersion '29.0.2'

    defaultConfig {
       ...

        buildConfigField 'boolean', 'SOME_SETTING_ENABLED', project.getProperties().get("some_setting_enabled") ?: "false"

        buildConfigField 'String', "API_URL", "\"<https://some-api-url.com/>\""
    }
you can then access via BuildConfig.SOME_SETTING_ENABLED and Buildconfig.API_URL
I think you can also access env variables via System.getenv(‘API_TOKEN’) within the build.gradle file
2 Views