Hi i am new in mobile development. I would like to...
# android
j
Hi i am new in mobile development. I would like to ask if there is something like .env in android development? Thanks
m
I don't know what is a .env, can you explain what you are looking to achieve ?
☝️ 1
j
.env in web development is where the sensitive keys are stored like private API keys, credentials, etc. @Michael Bernier
a
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
Thank you so much @Asad Ali. Will look into this
🤗 2
c
You can also just create straight up environment variables.
s
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