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

Not working for iOS Archive adhoc (often) #432

Open
luatnd opened this issue Mar 16, 2020 · 9 comments
Open

Not working for iOS Archive adhoc (often) #432

luatnd opened this issue Mar 16, 2020 · 9 comments

Comments

@luatnd
Copy link

luatnd commented Mar 16, 2020

I notice that if I archive the ios app 10 times
react-native-config does not work 4 times.
All configuration value are empty.

This issue also appears on dev mode, as I can see after press Run button on xCode, then check the file content:

$ cat node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m
Output:
$  #define DOT_ENV @{  };

Expected:

#define DOT_ENV @{  ....THE KEY AND VALUE IN .ENV FILE MUST BE HERE... };

Here my xCode build log of react-native-config pkg:

going to read env file from root folder <MY_SENSITIVE_PROJECT_ROOT>/ios/Pods/../..
**************************
*** Missing .env file ****
**************************
read dotenv {}
Wrote to <MY_SENSITIVE_PROJECT_ROOT>/ios/Pods/../../node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m

Here my react-native info output:

System:
    OS: macOS Mojave 10.14.4
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 81.95 MB / 8.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.6.0 - ~/.nvm/versions/node/v12.6.0/bin/node
    Yarn: 1.10.1 - /usr/local/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v12.6.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 23, 25, 26, 28, 29
      Build Tools: 28.0.3, 29.0.2
      System Images: android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom_64
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 11.3/11C29 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.5 => 0.61.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1
    react-native-pushdy: 0.0.11
    react-native-swift-cli: 2.3.0
@luancurti
Copy link
Collaborator

@luatnd please use the latest version 1.0.0 and test again

@rajatrao777
Copy link

rajatrao777 commented Mar 20, 2020

Hi,
I am using this package for env config, android works fine but in iOS it was able to read the file but not the content, because of spacing issues it should be like API_KEY='abc' and not API_KEY = 'abc',anyhow worked :)
Regarding your issue
I think you are running it from xcode, can you run from terminal using package scripts and check?

@luancurti
Copy link
Collaborator

@rajatrao777 yeah!

You can run passing the current scheme like this

xcodebuild -workspace ios/your_project.xcworkspace -scheme your_scheme -configuration Release or Debug

@zakton5
Copy link

zakton5 commented Mar 23, 2020

I am having a unique issue with iOS as well. It seems that it always uses the .env contents of the previous build. So if I build for Dev and then Prod, the Prod build will use the .env.development. Then if I build for Prod again it will correctly use the .env.prod.

@luancurti
Copy link
Collaborator

luancurti commented Mar 23, 2020

@zakton5 do you have added the script for the scheme in the Pre-actions following this steps?


Start by creating a new scheme:

In the Xcode menu, go to Product > Scheme > Edit Scheme
Click Duplicate Scheme on the bottom
Give it a proper name on the top left. For instance: "Myapp (staging)"
Then edit the newly created scheme to make it use a different env file. From the same "manage scheme" window:

Expand the "Build" settings on left
Click "Pre-actions", and under the plus sign select "New Run Script Action"
Where it says "Type a script or drag a script file", type:
echo ".env.staging" > /tmp/envfile   # replace .env.staging for your file```

@zakton5
Copy link

zakton5 commented Mar 24, 2020

@luancurti I did follow that step but I put the script under the Run build scripts accidentally. I changed it to be under Build and now it works. Thank you!

@luatnd
Copy link
Author

luatnd commented Jun 1, 2020

@luatnd please use the latest version 1.0.0 and test again

Thanks, I'm using 1.1.0 and it still uses the default .env file instead of .env.dev or .env.prod

@luatnd
Copy link
Author

luatnd commented Jun 1, 2020

I solved this issue.
Follow the docs would not work in my case. I need to do sth different bellow:

FYI, I'm using multiple env file:

  • .env.dev for debug
  • .env.prod for adhoc & build

As I debugged the node_modules/react-native-config/ios/ReactNativeConfig/ReadDotEnv.rb file, I found the problem is RNConfig cannot read the /tmp/envfile content if I use pre-action of Run & Archive scheme. The reason is those pre-action will run after RNConfig build.

To correctly set the /tmp/envfile content, I use Build scheme instead of Run & Archive:

Scheme > Build > Pre-action:

if [ "${CONFIGURATION}" == "Debug" ]; then
  osascript -e "display notification \"RNConfig Generate Preparation: .env.dev ~${CONFIGURATION}~ \""
  echo ".env.dev" > /tmp/envfile
else
  osascript -e "display notification \"RNConfig Generate Preparation: .env.prod ~${CONFIGURATION}~ \""
  echo ".env.prod" > /tmp/envfile
fi

Remember to choose Provide build settings from dropdown so that bash can access CONFIGURATION env:
image

To verify that RNConfig work correctly, read the xCode build log:
image

@Volekss
Copy link

Volekss commented Dec 24, 2020

Thanks @luatnd , it worked like a charm

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

5 participants