lugg / react-native-config

Bring some 12 factor love to your mobile apps!
MIT License
4.82k stars 657 forks source link

[Android] Getting .env when assemblerelease #704

Open 22mSqRi opened 1 year ago

22mSqRi commented 1 year ago

Hi, everyone. I want to each .env file with product flavor. But when I use ./gradlew assemblerelease, builder show Missing .env file message and no setting environment information.

build.gradle

project.ext.envConfigFiles = [
    debug: ".env.aaa",
    release: ".env.bbb"
]

    flavorDimensions 'flavors'
    productFlavors {
        aaa {
            dimension 'flavors'
        }

When I use Build Variants command on Android Studio and run-android command, environment information is setting correct.

npx react-native run-android --variant AaaRelease

How should I do setting environment information when assemblerelease?

justin-tay commented 1 year ago

You can try ./gradlew assembleAaaRelease

The file that determines the .env to use can be seen at https://github.com/luggit/react-native-config/blob/master/android/dotenv.gradle. If you can't get it to work you can edit node_modules/react-native-config/android/dotenv.gradle and add println to debug the variables.

That said by right your project.ext.envConfigFiles should looks something like

project.ext.envConfigFiles = [
    aaadebug: ".env.aaa",
    aaarelease: ".env.aaa",
    bbbdebug: ".env.bbb",
    bbbrelease: ".env.bbb"
]
BoilingOil commented 1 year ago

If you're using any other name than the default (plain old ".env"), then you need to specify this:

// ADD THIS
project.ext.defaultEnvFile = "path/to/.env.file"
// above this
project.ext.envConfigFiles = [
...

Otherwise the library will keep looking for ".env" when it's been renamed to ".env.otherwise"

Maybe add this to the docs, whoever supports this library.

midrizi commented 1 year ago

@BoilingOil

project.ext.defaultEnvFile = "path/to/.env.file"

This doesn't do anything.

BoilingOil commented 1 year ago

Really, nothing?

I use this in my project currently. Maybe the path to your .envfile needs correction.

Sahil6458 commented 1 year ago

Try this. Maybe there is permission issue. https://github.com/luggit/react-native-config/issues/541#issuecomment-1491388207

cjadhav commented 5 months ago

@BoilingOil, Yeah, setting Default env solves the issue. But it's not be useful for using with CICD when want to release build in single commit.