DEV Community

Cover image for A fix for ‘FirebaseCore/FirebaseCore.h file not found’ when using cordova-plugin-firebasex
Manuel Heidrich
Manuel Heidrich

Posted on • Originally published at manuel-heidrich.dev

A fix for ‘FirebaseCore/FirebaseCore.h file not found’ when using cordova-plugin-firebasex

When building a Cordova application chances are that you might want to integrate Google Firebase, whether for push notifications, analytics or authentication. Chances also are that like me you would use cordova-plugin-firebasex as it seems to be the most advanced and most actively maintained firebase plugin out there. In my case the extensive Ionic Native wrapper is a plus as well.

As extensive and well-maintained cordova-plugin-firebasex is, there are some quirks that can drive you crazy. One of them is the FirebaseCore/FirebaseCore.h file not found issue on iOS. This issue occurs mostly when running cordova prepare ios, after a fresh checkout for example or if you had to delete the platforms and plugins folders for some other reason. For me the issue occurs literally every time, even so I made sure all pods are up to date (as the plugin docs and issues suggest).

The only thing that seems to work well all the time is removing and re-adding the plugin every time after cordova prepare. This can be a cumbersome task, as you might want to keep the plugins's exact version as well as all custom configuration (which will be removed from package.json on cordova plugin rm).

Recently I just had enough (and sometimes I'am super lazy), so I wrote a script to automate the removing and re-adding of cordova-plugin-firebasex with all it's configuration from package.json.

To hopefully make someone else’s life a little easier as well, I decided to share my script with you, have fun!

const packageJson = require('../package.json');
const { spawn } = require('child_process');

function reinstallFirebase() {
  console.log(`Starting to re-install cordova-plugin-firebasex... Go grab some ☕️ or 🍔 while I'm at it. I will get back to you, as soon as I'm done!`);

  const firebaseVersion = packageJson.dependencies['cordova-plugin-firebasex'];

  let command = `ionic cordova plugin remove cordova-plugin-firebasex && ionic cordova plugin add cordova-plugin-firebasex@${firebaseVersion}`;

  const firebaseOptions = packageJson.cordova.plugins['cordova-plugin-firebasex'];

  for (const option in firebaseOptions) {
    if (firebaseOptions.hasOwnProperty(option)) {
      const value = firebaseOptions[option];

      command += ` --variable ${option}=${value}`;
    }
  }

  const npm = spawn(command, {
    cwd: process.cwd(),
    env: process.env,
    shell: true,
  });

  npm.stdout.on('data', (data) => {
    console.log(data.toString());
  });

  npm.on('close', (code) => {
    console.log(`🎉 Fixed firebase for you! 🔥`);
  });
}

reinstallFirebase();
Enter fullscreen mode Exit fullscreen mode

(I put this script in scripts/reinstall-firebase.js and added ”rf”: “node scripts/reinstall-firebase.js” to scripts in package.json.)

Top comments (0)