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

Availability in Build settings and Info.plist instructions work locally on MAC but not on Circle CI #409

Open
JanithaR opened this issue Nov 15, 2019 · 15 comments

Comments

@JanithaR
Copy link

The vars are always correctly populated when building/archiving locally on my MAC but always empty when built/archived on Circle CI.

I'm not really sure what other information to give on this other than that. Basically, I ran into this problem when integrating Codepush to my app, where they expect the keys to be defined in the Info.plist file. I took the traditional route of specifying build settings as a temporary workaround for the moment.

Let me know how I can help with any additional logs or similar.

@luis-f-lins
Copy link

I'm also having this problem, but we're using Bitrise for CI/CD

@JanithaR
Copy link
Author

JanithaR commented Jan 7, 2020

Check #391

@tpucci
Copy link

tpucci commented Jan 8, 2020

Perhaps this will help: #391 (comment)

@twelve17
Copy link

#391 (comment) Didn't apply in my case (I don't see the Build input file cannot be found: GeneratedDotEnv.m error). The app just always ends up with a Info.plist with empty values where the env values should be at. Unless I run it again. I'm going to try the other workaround in #391 (comment).

@lucianomlima
Copy link

Have the same problem with Bitrise. Defined secrets and env vars correctly there, but get AAPT: error: resource string/FACEBOOK_APP_ID (aka com.myapp.example/FACEBOOK_APP_ID) not found.

Add .env file to repository seems strange to me.

@shaddeen
Copy link

Did anyone figure this out? Same issue on Bitrise

@luis-f-lins
Copy link

luis-f-lins commented Jul 24, 2020

@lucianomlima @shaddeen on Bitrise, I've used a temporary fix based on #391 (comment). I've created the following .js script and put it in the source folder. Then, in the Bitrise workflow (I've personally changed both the staging and production workflows), right after the yarn install step, I added a Script Runner step, to run the following script with node. This fixed the problem, and I've been using it for a few months now. Hope this helps you guys!

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('====================================================================');

    let isProduction;
    try {
      if(fs.existsSync('./.env.production')) {
        isProduction = true;
        console.log('production environment');
      } else {
        isProduction = false;
        console.log('staging environment');
      }
    } catch (err) {
        console.error(err);
    }
    const envfile = isProduction ? await readFile('./.env.production', 'utf-8') : await readFile('./.env', 'utf-8');
    const plist = await readFile('./ios/[***  PROJECT_FOLDER  ***]/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/[***  PROJECT_FOLDER  ***]/Info.plist', plistupdated, 'utf-8');
    await writeFile('./ios/[***  PROJECT_FOLDER  ***]/Info.plist.bak', plist, 'utf-8');
  } catch (e) {
    console.error(e);
    console.error(`Unable to read .env file`);
    process.exit(1);
  }
}

main();

@shaddeen
Copy link

@luis-f-lins thanks! Do you have something for android?

@luis-f-lins
Copy link

@luis-f-lins thanks! Do you have something for android?

I don’t think this problem occurs on Android, because it’s related to the Info.plist file, which is an iOS file.

@lucianomlima
Copy link

lucianomlima commented Jul 25, 2020

@lucianomlima @shaddeen on Bitrise, I've used a temporary fix based on #391 (comment). I've created the following .js script and put it in the source folder. Then, in the Bitrise workflow (I've personally changed both the staging and production workflows), right after the yarn install step, I added a Script Runner step, to run the following script with node. This fixed the problem, and I've been using it for a few months now. Hope this helps you guys!

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('====================================================================');

    let isProduction;
    try {
      if(fs.existsSync('./.env.production')) {
        isProduction = true;
        console.log('production environment');
      } else {
        isProduction = false;
        console.log('staging environment');
      }
    } catch (err) {
        console.error(err);
    }
    const envfile = isProduction ? await readFile('./.env.production', 'utf-8') : await readFile('./.env', 'utf-8');
    const plist = await readFile('./ios/[***  PROJECT_FOLDER  ***]/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/[***  PROJECT_FOLDER  ***]/Info.plist', plistupdated, 'utf-8');
    await writeFile('./ios/[***  PROJECT_FOLDER  ***]/Info.plist.bak', plist, 'utf-8');
  } catch (e) {
    console.error(e);
    console.error(`Unable to read .env file`);
    process.exit(1);
  }
}

main();

I have been resolved in a similar way, but using a bash script.

@shaddeen
Copy link

@luis-f-lins thanks! Do you have something for android?

I don’t think this problem occurs on Android, because it’s related to the Info.plist file, which is an iOS file.

Strange, I have the exact same issue with Android

@jaexplorer
Copy link

@luis-f-lins I'm still having issues with Bitrise, are you able to help me?

@luis-f-lins
Copy link

@luis-f-lins I'm still having issues with Bitrise, are you able to help me?

Can you describe a little more of what you’re running into?

@jaexplorer
Copy link

Managed to figure out I was trying to fix the wrong iOS target, all good

@geraintwhite
Copy link

The issue with the first CI build not having the Info.plist processed is that the build relies on tmp.xcconfig existing at the start of the build (seemingly before the pre-action script is run).

My workaround is to run touch ios/tmp.xcconfig at the start of my CI process so that all builds will have the Info.plist processed correctly.

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

8 participants