lugg / react-native-config

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

JS part returns empty always #666

Closed indapublic closed 2 years ago

indapublic commented 2 years ago
System:
    OS: macOS 12.4
    CPU: (8) arm64 Apple M1
    Memory: 119.58 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 15.14.0 - ~/.nvm/versions/node/v15.14.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 7.7.6 - ~/.nvm/versions/node/v15.14.0/bin/npm
    Watchman: 2022.06.13.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8609683
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.12 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.66.1 => 0.66.1
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Android

Android Studio Chipmunk | 2021.2.1 Patch 1
Build #AI-212.5712.43.2112.8609683, built on May 19, 2022
Runtime version: 11.0.12+0-b1504.28-7817840 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.4
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 8
Registry: external.system.auto.import.disabled=true

package.json

"android": "ENVFILE=.env.development react-native run-android --variant=developmentdebug --appIdSuffix development",
"android:staging": "ENVFILE=.env.staging react-native run-android --variant=stagingdebug --appIdSuffix staging",

Added println to dotenv.gradle

System.out.println(env);

project.ext.set("env", env)

Result:

Android part is:

> Configure project :app
Reading env from: .env.staging
{ENV=staging, API_URL=https://api.domain.my/api/v1, SENTRY_DSN=https://aaaaaaaaaaaaa@bbbbbbb.ingest.sentry.io/cccccccc, MIXPANEL_TOKEN=dddddddddd, MAJOR_VERSION=1, MINOR_VERSION=2, PATCH_VERSION=1, PRE_RELEASE=STAGING}

but

import config from "react-native-config";

console.log(config);

is empty

indapublic commented 2 years ago

cp env/.env.staging .env && react-native run-android --variant=stagingdebug seems working for me

but if I'm changing applicationId via productFlavors - JS part returns empty object again

build_config_package doesn't help