-
Notifications
You must be signed in to change notification settings - Fork 658
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
Availability in Build settings and Info.plist problem #391
Comments
In your scheme settings, Build -> Pre-actions
|
Since the update from 0.11.7 to 0.12.0 all variables used in info.plist are only updated on the second build. The Build log shows RN-config updates the variables correct on first build, but the info.plist in the produced app is not updated correspondingly. This was better in v0.11.7 when plist-preprocessing was possible using the Any thoughs on this? |
Looks like @rafaelmaeuer 's comment and #409 are related. |
why was the code generating, GeneratedInfoPlistDotEnv.h removed? |
Yep
I don't really understand the context to give an answer to this. |
Yeah so on my circle ci build, I'm now running this custom script which is a temporary measure. patches in the .env file into info.plist #!/usr/bin/env node
const fs = require('fs');
const dotenv = require('dotenv');
const promisify = require('util').promisify;
const writeFile = promisify(fs.writeFile);
const readFile = promisify(fs.readFile);
async function main() {
try {
console.log('===================== THIS IS A TEMPORARY SCRIPT ===================');
console.log('===================== UPDATING Info.plist with .env ================');
console.log('====================================================================');
console.log('see Issue: https://github.com/luggit/react-native-config/issues/391');
const envfile = await readFile('./.env', 'utf-8');
const plist = await readFile('./ios/medapp/Info.plist', 'utf-8');
const env = dotenv.parse(Buffer.from(envfile));
let plistupdated = plist;
Object.entries(env).forEach(([key,value]) => {
plistupdated = plistupdated.replace(new RegExp(`\\$\\(${key}\\)`, 'g'), value);
});
await writeFile('./ios/medapp/Info.plist', plistupdated, 'utf-8');
await writeFile('./ios/medapp/Info.plist.bak', plist, 'utf-8');
} catch (e) {
console.error(e);
console.error(`Unable to read .env file`);
process.exit(1);
}
}
main(); |
My temporary workaround is to remove the app and build again:
|
@export-mike I'm using Bitrise as my CI/CD platform, and your custom script worked for me, thank you. I hope a proper fix is released soon. |
Hi ! If your issue is (file located at s.script_phase = {
name: 'Config codegen',
script: %(
- set -ex
- HOST_PATH="$SRCROOT/../.."
- "${PODS_TARGET_SRCROOT}/ios/ReactNativeConfig/BuildDotenvConfig.rb" "$HOST_PATH" "${PODS_TARGET_SRCROOT}/ios/ReactNativeConfig"
- ),
+ set -ex
+ HOST_PATH="$SRCROOT/../.."
+ ${PODS_TARGET_SRCROOT}/ios/ReactNativeConfig/BuildDotenvConfig.rb $HOST_PATH ${PODS_TARGET_SRCROOT}/ios/ReactNativeConfig
+ ),
execution_position: :before_compile,
- input_files: ['$(SRCROOT)/ReactNativeConfig/BuildDotenvConfig.rb']
+ input_files: ['$PODS_TARGET_SRCROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb'],
+ output_files: ['$PODS_TARGET_SRCROOT/ios/ReactNativeConfig/GeneratedDotEnv.m']
}
s.source_files = 'ios/**/*.{h,m}' Explanation: The custom pod script generates the Source: http://www.gietal.net/blog/xcode10-and-prebuild-script-output-files-xcfilelist |
@rafaelmaeuer did you end up using a workaround that worked? Currently my workaround is to build the first env of the app twice. |
I didn't had the time to test any workaround yet, so I am doing the same: building the app twice is annoying but it works... |
@tpucci Thanks for your suggestion (#391 (comment)), it's the only thing which seems to work for me, only issue is remembering to edit the podspec if/when node_modules is rebuilt 😩 |
@leemcmullen I recommend that you use 'patch-package' in order not to worry about that. |
@tpucci Good idea, thanks Thomas! 👍 |
anyplans to release this patch as a fix? |
If anyone needs #391 (comment) as a permanent patch:
yarn add --dev patch-package # or npm install -D patch-package
...
"scripts": {
...
"postinstall": "patch-package",
...
},
... In our script we also need react-native-inhibit-warnings and jetifier "postinstall": "react-native-inhibit-warnings && jetifier && patch-package",
(Note I removed whitespace changes from @tpucci 's patch) Confirmed working on:
|
@jacobcabantomski-ct any reason why this needs to stay as a match and not merged, I've seen others fork the project just to make this change |
Resolves #391 Based on #391 (comment) Add correct output file. Update input file to use correct root path.
Thanks for adding the patch to the latest release, but the plist variables on first build are still not working for me. Can someone post a working example on how to configure this correctly? EDIT: I figured it out by myself
Some further thoughts:
|
@rafaelmaeuer Can your steps be added to the README, or should a more automatic solution be investigated? |
If this is wanted I can update the readme to include my solution. @luancurti what do you think? |
working on: "react-native-config": "1.2.1", |
I think it's a good idea to add this |
This is my solution :
|
Worked for me. |
I'm using pod generated xcconfig files, so I created a post_install that appends #include? "tmp.xcconfig"
|
I was having the same issue but I found that my bash script was not properly written in the prebuild scripts. It should be like
also, you have to write in the input |
It was not very clear from README instructions where to add the script to generate The correct place where to add Otherwise the approach seems to work correctly and you don't need to make loads of manual work as described in #391 (comment). PS Note that variables don't have UPD Apparently one needs to setup same Pre-Action for the Archive schema, so values are available during the Archive build. And likely for every single schema you use. So I decided to to run this script manually before invoking Xcode to avoid maintaining same code in multiple places. |
Ty bro! That was my issue |
This is my solution This is my pre action build script, I use # Type a script or drag a script file from your workspace to insert its path.
# exec > ${PROJECT_DIR}/prebuil#d.log 2>&1
# ie, copy .env.development to /tmp/envfile
cp "${SRCROOT}/../.env.${RNCONFIG_ENVIRONMENT}" "/tmp/envfile"
# same as always, not changes here
"${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb" "${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig" To setup a user defined variable, do this, Add a variable called Remember to create both env files in your root react native project, ie, .env.development and .env.production The final changed is to modified the file diff --git a/old.txt b/new.txt
index 4e9fd89..51bd95e 100644
--- a/old.txt
+++ b/new.txt
@@ -14,28 +14,30 @@ def read_dot_env(envs_root)
# pick a custom env file if set
if File.exist?('/tmp/envfile')
custom_env = true
- file = File.read('/tmp/envfile').strip
+ raw = File.read('/tmp/envfile').strip
else
custom_env = false
file = ENV['ENVFILE'] || defaultEnvFile
end
-
dotenv = begin
# https://regex101.com/r/cbm5Tp/1
dotenv_pattern = /^(?:export\s+|)(?<key>[[:alnum:]_]+)\s*=\s*((?<quote>["'])?(?<val>.*?[^\\])\k<quote>?|)$/
- path = File.expand_path(File.join(envs_root, file.to_s))
- if File.exist?(path)
- raw = File.read(path)
- elsif File.exist?(file)
- raw = File.read(file)
- else
- defaultEnvPath = File.expand_path(File.join(envs_root, "#{defaultEnvFile}"))
- unless File.exist?(defaultEnvPath)
- # try as absolute path
- defaultEnvPath = defaultEnvFile
+ unless custom_env
+ path = File.expand_path(File.join(envs_root, file.to_s))
+ if File.exist?(path)
+ raw = File.read(path)
+ elsif File.exist?(file)
+ raw = File.read(file)
+ else
+ defaultEnvPath = File.expand_path(File.join(envs_root, "#{defaultEnvFile}"))
+ puts defaultEnvPath
+ unless File.exist?(defaultEnvPath)
+ # try as absolute path
+ defaultEnvPath = defaultEnvFile
+ end
+ raw = File.read(defaultEnvPath)
end
- raw = File.read(defaultEnvPath)
end
raw.split("\n").inject({}) do |h, line| I recommend to use |
This worked for me as well. Im developing with multiple targets (dev, stage, prod). So I had to add Pre-actions to every target. |
leaving here a note in case someone else has the same issue Running manually after
|
@adrach when running this commande manually, how do you determine what the BUILD_DIR used by the script is ? |
Resolves lugg/react-native-config#391 Based on lugg/react-native-config#391 (comment) Add correct output file. Update input file to use correct root path.
Resolves lugg/react-native-config#391 Based on lugg/react-native-config#391 (comment) Add correct output file. Update input file to use correct root path.
where we must to add below code in step 6 of
Availability in Build settings and Info.plist
section:"${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb" "${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig"
The text was updated successfully, but these errors were encountered: