Search code examples
iosreact-nativefbsdk

Linking error in react native IOS app after using Facebook SDK


I am using RNFirebase.io and trying its starter kit. It does work fine but I started getting these below errors after setting up Facebook SDK.

ld: warning: Auto-Linking supplied '/Users/xyz/Documents/FacebookSDK/FBSDKLoginKit.framework/FBSDKLoginKit', framework linker option at /Users/xyz/Documents/FacebookSDK/FBSDKLoginKit.framework/FBSDKLoginKit is not a dylib
ld: warning: Auto-Linking supplied '/Users/xyz/Documents/FacebookSDK/FBSDKShareKit.framework/FBSDKShareKit', framework linker option at /Users/xyz/Documents/FacebookSDK/FBSDKShareKit.framework/FBSDKShareKit is not a dylib
ld: warning: Auto-Linking supplied '/Users/xyz/Documents/FacebookSDK/FBSDKCoreKit.framework/FBSDKCoreKit', framework linker option at /Users/xyz/Documents/FacebookSDK/FBSDKCoreKit.framework/FBSDKCoreKit is not a dylib
ld: warning: Auto-Linking supplied '/Users/xyz/Documents/FacebookSDK/Bolts.framework/Bolts', framework linker option at /Users/xyz/Documents/FacebookSDK/Bolts.framework/Bolts is not a dylib
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_FBSDKAccessToken", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKAccessToken.o)
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKGraphRequestConnectionContainer.o)
      objc-class-ref in libRCTFBSDK.a(RCTConvert+FBSDKAccessToken.o)
  "_OBJC_CLASS_$_FBSDKAppEvents", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKAppEvents.o)
  "_OBJC_CLASS_$_FBSDKAppInviteContent", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKAppInviteDialog.o)
  "_OBJC_CLASS_$_FBSDKAppInviteDialog", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKAppInviteDialog.o)
  "_OBJC_CLASS_$_FBSDKApplicationDelegate", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_FBSDKGameRequestContent", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKGameRequestDialog.o)
  "_OBJC_CLASS_$_FBSDKGameRequestDialog", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKGameRequestDialog.o)
  "_OBJC_CLASS_$_FBSDKGraphRequest", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKGraphRequestConnectionContainer.o)
  "_OBJC_CLASS_$_FBSDKGraphRequestConnection", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKGraphRequestConnectionContainer.o)
  "_OBJC_CLASS_$_FBSDKHashtag", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTConvert+FBSDKSharingContent.o)
  "_OBJC_CLASS_$_FBSDKLikeControl", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKLikeControlManager.o)
  "_OBJC_CLASS_$_FBSDKLoginButton", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKLoginButtonManager.o)
  "_OBJC_CLASS_$_FBSDKLoginManager", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKLoginManager.o)
  "_OBJC_CLASS_$_FBSDKMessageDialog", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKMessageDialog.o)
  "_OBJC_CLASS_$_FBSDKSendButton", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKSendButtonManager.o)
  "_OBJC_CLASS_$_FBSDKSettings", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKInitializer.o)
  "_OBJC_CLASS_$_FBSDKShareAPI", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKShareAPI.o)
  "_OBJC_CLASS_$_FBSDKShareButton", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKShareButtonManager.o)
  "_OBJC_CLASS_$_FBSDKShareDialog", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTFBSDKShareDialog.o)
  "_OBJC_CLASS_$_FBSDKShareLinkContent", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTConvert+FBSDKSharingContent.o)
  "_OBJC_CLASS_$_FBSDKShareOpenGraphAction", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTConvert+FBSDKSharingContent.o)
  "_OBJC_CLASS_$_FBSDKShareOpenGraphContent", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTConvert+FBSDKSharingContent.o)
  "_OBJC_CLASS_$_FBSDKShareOpenGraphObject", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTConvert+FBSDKSharingContent.o)
  "_OBJC_CLASS_$_FBSDKSharePhoto", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTConvert+FBSDKSharingContent.o)
  "_OBJC_CLASS_$_FBSDKSharePhotoContent", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTConvert+FBSDKSharingContent.o)
  "_OBJC_CLASS_$_FBSDKShareVideo", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTConvert+FBSDKSharingContent.o)
  "_OBJC_CLASS_$_FBSDKShareVideoContent", referenced from:
      objc-class-ref in libRCTFBSDK.a(RCTConvert+FBSDKSharingContent.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solutions that I have already tried - 1. Added '~/Documents/FacebookSDK' in 'framework search Paths' in build settings section. 2. Also checked that libRCTFBSDK.a is added in 'Link Binary with Libraries'

What should I do to fix it?


Solution

  • I had same problem and the solution is very easy, but the solution is not obivious!..

    Let's go.

    Use this steps iOS Guide

    But on step 7.

    Install the file ios_setup.js by executing the following command in a command prompt at your project's root folder.

    I recommend you enter in Raw iOS install script

    on terminal in root ios folder use.

    vi ios_setup.js

    and paste

    /*
     Copyright 2004-present Facebook. All Rights Reserved.
    
     A node script to help set up FBSDK frameworks for use with https://github.com/facebook/react-native-fbsdk
     after you have already run `rnpm install react-native-fbsdk`.
    
     Note that you need to create a Facebook App in https://developers.facebook.com/
     and get the Facebook APP ID and Facebook APP Name in order to set up the Info.plist.
     Usage:
    
     1. add to the 'script' section in package.json of your react-native project the following:
        '"ios:setup": "node ./node_modules/react-native-fbsdk/bin/ios_setup.js"'.
     2. do 'npm run ios:setup <AppID> <AppName>'.
     */
    
    'use strict';
    
    /* eslint-disable no-console */
    
    const AdmZip = require('adm-zip');
    const ProgressBar = require('progress');
    
    const fall = require('fastfall')();
    const fs = require('fs');
    const got = require('got');
    const path = require('path');
    const plist = require('plist');
    const pump = require('pump');
    const xcode = require('xcode');
    
    const progressBarPattern = '  downloading [:bar] :rate/bps :percent :etas';
    const frameworkDir = 'ios/Frameworks/';
    const zipFileName = 'fbsdk.zip';
    const zipFilePath = path.join(frameworkDir, zipFileName);
    const frameworkUrl = 'https://origincache.facebook.com/developers/resources/?id=facebook-ios-sdk-current.zip';
    
    // Get Facebook App ID and App Name.
    if (process.argv.length <= 3) {
      console.log('Usage: ios_setup.js <APPID> <APPNAME>');
      process.exit(-1);
    }
    
    const appId = process.argv[2];
    const appName = process.argv[3];
    
    function downloadFbSdk (next) {
      try {
        fs.accessSync(frameworkDir, fs.F_OK);
      } catch (e) {
        fs.mkdirSync(frameworkDir);
      }
    
      var bar = null;
      var download = got.stream(frameworkUrl)
        .on('data', chunk => {
          bar.tick(chunk.length);
        })
        .on('response', res => {
          const len = parseInt(res.headers['content-length'], 10);
          bar = new ProgressBar(progressBarPattern, {
            complete: '=',
            incomplete: ' ',
            width: 20,
            total: len,
          });
        });
    
      var writeToFile = fs.createWriteStream(zipFilePath);
      pump(download, writeToFile, next);
    }
    
    function unzipFramework (next) {
      console.log('Unzipping the framework');
      const zip = new AdmZip(zipFilePath);
      zip.extractAllTo(frameworkDir, true);
      fs.unlinkSync(zipFilePath);
      console.log('Framework Unzipped!');
      next();
    }
    
    function correctSearchPaths (next) {
      const rctfbsdkProjectPath = './node_modules/react-native-fbsdk/ios/RCTFBSDK.xcodeproj/project.pbxproj';
      const rctfbsdkProject = xcode.project(rctfbsdkProjectPath);
      rctfbsdkProject.parse(function (err) {
        if (err) {
          return next(err);
        }
        rctfbsdkProject.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/../../../ios/Frameworks"');
        fs.writeFileSync(rctfbsdkProjectPath, rctfbsdkProject.writeSync());
        console.log('Updated RCTFBSDK FRAMEWORK_SEARCH_PATHS');
        next();
      });
    }
    
    function updateFBSDKFrameworks (next) {
      const files = fs.readdirSync('./ios/');
      var myProjName = files.filter((f) => { return f.substr(-10) === '.xcodeproj'; })[0];
      const myProjPath = path.join('./ios/', myProjName, '/project.pbxproj');
      myProjName = myProjName.replace('.xcodeproj', '');
      console.log('Updating target:' + myProjName + ' at ' + myProjPath + ' ...');
    
      const myProj = xcode.project(myProjPath);
      myProj.parse(function (err) {
        if (err) {
          return next(err);
        }
        myProj.pbxCreateGroup('Frameworks', './ios/Frameworks');
    
        // NOTE: Assumes first target is the app.
        const target = myProj.getFirstTarget().uuid;
        myProj.addFramework('./ios/Frameworks/FBSDKCoreKit.framework', { 'customFramework': true, 'target': target, 'link': true });
        myProj.addFramework('./ios/Frameworks/FBSDKShareKit.framework', { 'customFramework': true, 'target': target, 'link': true });
        myProj.addFramework('./ios/Frameworks/FBSDKLoginKit.framework', { 'customFramework': true, 'target': target, 'link': true });
    
        // WARNING: this will overwrite any existing search paths
        myProj.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/Frameworks/"');
        fs.writeFileSync(myProjPath, myProj.writeSync());
        console.log('Finished updating ' + myProjPath);
    
        next(null, files);
      });
    }
    
    function updatePlist (files, next) {
      console.dir(files);
      var plistDirPath = '';
      files.map(function (file) {
        return path.join('./ios/', file);
      }).filter(function (file) {
        return fs.statSync(file).isDirectory();
      }).forEach(function (file) {
        if (fs.readdirSync(file).indexOf('Base.lproj') !== -1) {
          plistDirPath = file;
        }
      });
      const plistFilePath = path.join(plistDirPath, '/Info.plist');
      const plistFile = fs.readFileSync(plistFilePath, 'utf8');
      const plistObject = plist.parse(plistFile);
      plistObject.CFBundleURLTypes = [{CFBundleURLSchemes: ['fb' + appId]}];
      plistObject.FacebookAppID = appId;
      plistObject.FacebookDisplayName = appName;
      plistObject.LSApplicationQueriesSchemes = ['fbapi', 'fb-messenger-api', 'fbauth2', 'fbshareextension'];
      plistObject.NSLocationWhenInUseUsageDescription = '';
      fs.writeFileSync(plistFilePath, plist.build(plistObject));
      console.log('Finished updating ' + plistFilePath);
      next();
    }
    
    function done (err) {
      if (err) {
        console.error(err);
      } else {
        console.log('DONE!');
      }
    }
    
    fall([downloadFbSdk, unzipFramework, correctSearchPaths, updateFBSDKFrameworks, updatePlist], done);

    after this, execute the script

    node ios_setup.js 'fb_id_here' 'fb_app_name_here'

    follow the site.

    Hope to help you and others.