使用Facebook SDK后,在本机IOS应用程序中链接错误

时间:2017-11-20 10:22:49

标签: ios react-native fbsdk

我正在使用RNFirebase.io并尝试其入门套件。它确实工作正常,但我在设置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)

我已经尝试过的解决方案 - 1.在构建设置部分的“框架搜索路径”中添加了“〜/ Documents / FacebookSDK”。 2.还检查了“Link Binary with Libraries”中添加了libRCTFBSDK.a

我该怎么办才能修复它?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题并且解决方案非常简单,但解决方案并不明确!...

我们走吧。

使用以下步骤iOS Guide

但是在第7步。

  

通过在项目根文件夹的命令提示符中执行以下命令来安装文件ios_setup.js。

我建议你输入Raw iOS install script

在root ios文件夹的终端上使用。

vi ios_setup.js

并粘贴

/*
 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);

之后,执行脚本

node ios_setup.js 'fb_id_here' 'fb_app_name_here'

关注该网站。

希望能帮助你和其他人。