Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Getting correct .env with productFlavors #602

Open
moonjava2005 opened this issue Aug 9, 2021 · 7 comments
Open

[Android] Getting correct .env with productFlavors #602

moonjava2005 opened this issue Aug 9, 2021 · 7 comments

Comments

@moonjava2005
Copy link

Dear all,
I did as the document with .env file picker like this

project.ext.envConfigFiles = [
        debug                  : ".env",
        release                : ".env.production",
        adhoc                  : ".env.test",
        asiaRelease        : ".env.production",
        usRelease           : ".env.production",
]

And I setup my project with flavors like this

    flavorDimensions "env"

    productFlavors {
        asia_dev {
            dimension "env"
            applicationIdSuffix ".asia.dev"
        }
        asia {
            dimension "env"
            applicationIdSuffix ".asia"
        }
        us_dev {
            dimension "env"
            applicationIdSuffix ".us.dev"
        }
        us {
            dimension "env"
            applicationIdSuffix ".us"
        }
    }

As I expect when I make build with release, the flavor usRelease and asiaRelease will pick the ".env.production". However, it always picks the ".env" file
Could you guys help me what's going wrong in this case?
Thanks

@jonaxd1
Copy link

jonaxd1 commented Aug 27, 2021

I had my flavors like:

    flavorDimensions "sandbox"
    productFlavors {
        create("sandbox") {
            dimension = "sandbox"
            applicationIdSuffix = ".sandbox"
        }
    }

and envConfigFile like this

project.ext.envConfigFiles = [
        debug: ".sandbox.env",
        release: ".sandbox.env",
        anothercustombuild: ".sandbox.env",
        sandboxRelease: ".sandbox.env", // <-- ?
        sandbox: ".sandbox.env", // <-- ?
]

and successfully got the proper .env (Idk if it was by the penultimate, or last one)

@blogui91
Copy link

blogui91 commented Oct 2, 2021

@moonjava2005 Hello, did you solve this issue? I'm strugging with this as well.

I have these configuration.

project.ext.envConfigFiles = [
  productiondebug: ".env.production",
  productionrelease: ".env.production",
  developmentrelease: ".env.development",
  developmentdebug: ".env.development",
  stagingrelease: ".env.staging",
  stagingdebug: ".env.staging"
]

flavorDimensions "default"

  productFlavors {
      production {
        resValue "string", "app_name", "MyApp"
      }

      staging {
        applicationIdSuffix '.staging'
        resValue "string", "app_name", "MyApp Staging"
        // We can have build-specific configurations here. Like using applicationIdSuffix to create different package name (ex. ".staging")
      }

      development {
        applicationIdSuffix '.staging'
        resValue "string", "app_name", "MyApp Dev"
      }
  }
package.json

"scripts": {
    "android:staging": "react-native run-android --variant=stagingdebug",
    "android:staging-release": "react-native run-android --variant=stagingrelease",
    "android:dev": "react-native run-android --variant=developmentdebug",
    "android:dev-release": "react-native run-android --variant=developmentrelease",
    "android:prod": "react-native run-android --variant=productiondebug",
    "android:prod-release": "react-native run-android --variant=productionrelease"
}

Even if I speficy the ENVFILE in the script as below

package.json

"scripts": {
    "android:staging": "ENVFILE=.env.staging react-native run-android --variant=stagingdebug",
    "android:staging-release": "ENVFILE=.env.staging react-native run-android --variant=stagingrelease",
    "android:dev": "ENVFILE=.env.development react-native run-android --variant=developmentdebug",
    "android:dev-release": "ENVFILE=.env.development react-native run-android --variant=developmentrelease",
    "android:prod": "ENVFILE=.env.production react-native run-android --variant=productiondebug",
    "android:prod-release": "ENVFILE=.env.production react-native run-android --variant=productionrelease"
}

@MathieuUrstein
Copy link

My issue #616 may be related.

@david-allison
Copy link

If you're using applicationIdSuffix: Ensure that the package name is defined in defaultConfig in android/app/build.gradle

defaultConfig {
        // ...
        // required for react-native-config
        resValue "string", "build_config_package", "com.package_name_with_no_suffix"
}

@dgcong
Copy link

dgcong commented Oct 18, 2023

Thanks @david-allison it worked for me

@david-allison

This comment has been minimized.

@devethan
Copy link

devethan commented Nov 1, 2023

You should try this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants