lugg / react-native-config

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

3 environment set up not working in Android #596

Open harshal311989 opened 3 years ago

harshal311989 commented 3 years ago

hello team, Currently in my react native app i have 3 enviromnrt dev, test and live so i created .env file like .env.dev, .env.tst, and .env.live file and i set up android as per your document like below project.ext.envConfigFiles = [ debug: ".env.tst", release: ".env.tst", live: ".env.live", anothercustombuild: ".env", ]

buildTypes { debug { signingConfig signingConfigs.debug debuggable false minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } release { // Caution! In production, you need to generate your own keystore file. // see https://reactnative.dev/docs/signed-apk-android. signingConfig signingConfigs.release minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } live { // Caution! In production, you need to generate your own keystore file. // see https://reactnative.dev/docs/signed-apk-android. signingConfig signingConfigs.release minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } }

But when i create build i got error like below

Unable to find a matching variant of project :react-native-fbsdk:

Ite means all my third party plugin dont have live build type so how i can solve this issue? Rgiht now i have 30 plugins in my app and all are giving same error any idea how i can solve this?

carmelocatalfamo commented 3 years ago

@harshal311989 have you tried adding this line matchingFallbacks = ['release'] to your custom builds?

buildTypes: {
   debug: { ... }
   release: { ... }
   live {
     signingConfig signingConfigs.release
     minifyEnabled enableProguardInReleaseBuilds
     proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
     matchingFallbacks = ['release'] // Add this line
   }
}
keiches commented 3 years ago

Same to me. I added matchinFallbacks already like below.

buildTypes { ...... stage: { applicationIdSuffix ".stage" matchingFallbacks = ['release'] } ...... }

after build. then run. it's value is empty.

.env.stage TEST="tEST"

import Config from 'react-native-config' ...... Config.TEST ?

What should i do?

Please help. thank you

mattwoberts commented 2 years ago

Hi there. I have what I think is the same issue as this.

Specifically, I've added a enw buildType called releaseStaging, like this:

        releaseStaging {
            applicationIdSuffix ".staging"
            resValue "string", "CodePushDeploymentKey", '"**something**"'
            matchingFallbacks = ['release']
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }

I usually let the ENVFILE environemnt variable control which file it uses. But when running this new releaseStaging build, I find that my env.SOME_OPTION is null :(

I've tried to add this to see if it helps:

project.ext.envConfigFiles = [
   releasestaging: ".env.production",
    debug: ".env",
    release: ".env.production"
]

And still nothing. But if I switch back to release and run that, it works fine.

Any ideas what this could be, or what I could do to troubleshoot this?

I'm on the latest (1.4.5) version, and RN 0.66

Thanks!

mattwoberts commented 2 years ago

Aha - update for my issue.

Becuase I have a different application Id, it doesn't work. The className that is being used in the java is the one appended with the ".staging", and that means that the env vars are not being read.

To resolve this, I've added a line in my build.grade, in my custom buildType:

            resValue "string", "build_config_package", "com.myapp"

And now everything works :)

caolong0204 commented 1 year ago

Aha - update for my issue.

Becuase I have a different application Id, it doesn't work. The className that is being used in the java is the one appended with the ".staging", and that means that the env vars are not being read.

To resolve this, I've added a line in my build.grade, in my custom buildType:

            resValue "string", "build_config_package", "com.myapp"

And now everything works :)

it not work for me

SanjanaTailor commented 1 year ago

ot work for me

For me also it did not work me.

SteveLai524 commented 1 year ago

I also meet the issue. and i manual link to fix it...