You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

集成FCM后iOS编译报错:Library 'GoogleSignIn' not found

解决React Native iOS集成FCM后「Library 'GoogleSignIn' not found」编译错误

问题描述

我正在开发一款React Native iOS应用,集成Firebase Cloud Messaging (FCM)实现推送通知前运行完全正常。Android端集成FCM后仍能正常工作,但iOS版本无法编译,每次在Xcode中运行都会出现「Library 'GoogleSignIn' not found」错误。

相关文件内容

Podfile

# Enable modular headers globally
use_modular_headers!
def node_require(script)
   # Resolve script with node to allow for hoisting
   require Pod::Executable.execute_command('node', ['-p',
     "require.resolve(
       '#{script}',
       {paths: [process.argv[1]]},
     )", __dir__]).strip
 end

# Use it to require both react-native's and this package's scripts:
 node_require('react-native/scripts/react_native_pods.rb')
 node_require('react-native-permissions/scripts/setup.rb')


platform :ios, min_ios_version_supported
prepare_react_native_project!

setup_permissions([
  'LocationAlways',
  'LocationWhenInUse',
])

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

use_frameworks! :linkage => :static
$RNFirebaseAsStaticFramework = true

target 'OfferBoat' do
  
  rn_maps_path = '../node_modules/react-native-maps'
  pod 'react-native-google-maps', :path => rn_maps_path
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

   # Add GooglePlaces and GoogleMaps pods here
   pod 'GooglePlaces'
   pod 'GoogleMaps'

  target 'OfferBoatTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )
  end
end

AppDelegate.m

#import "AppDelegate.h"
#import <Firebase.h>
#import <React/RCTBundleURLProvider.h>
#import <GoogleMaps/GoogleMaps.h>
#import <GoogleSignIn/GoogleSignIn.h>
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];
  [GMSServices provideAPIKey:@"AIza...iY4.....Y...nYj...Q3G...g"];
  self.moduleName = @"OfferBoat";

  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  return [self bundleURL];
}

- (NSURL *)bundleURL
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

package.json

{
  "name": "OfferBoat",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@hookform/resolvers": "^3.5.0",
    "@notifee/react-native": "^7.8.2",
    "@react-native-async-storage/async-storage": "^1.23.1",
    "@react-native-community/datetimepicker": "^8.1.0",
    "@react-native-community/geolocation": "^3.3.0",
    "@react-native-firebase/app": "^20.4.0",
    "@react-native-firebase/messaging": "^20.4.0",
    "@react-native-google-signin/google-signin": "^12.2.1",
    "@react-navigation/bottom-tabs": "^6.5.20",
    "@react-navigation/native": "^6.1.17",
    "@react-navigation/native-stack": "^6.9.26",
    "@react-navigation/stack": "^6.3.29",
    "@reduxjs/toolkit": "^2.2.5",
    "@stripe/stripe-react-native": "^0.38.2",
    "@types/react-redux": "^7.1.33",
    "axios": "^1.7.2",
    "date-fns": "^3.6.0",
    "lottie-react-native": "^6.7.2",
    "react": "18.2.0",
    "react-hook-form": "^7.51.5",
    "react-native": "0.74.2",
    "react-native-calendars": "^1.1305.0",
    "react-native-gesture-handler": "^2.16.2",
    "react-native-get-random-values": "^1.11.0",
    "react-native-google-places-autocomplete": "^2.5.6",
    "react-native-image-crop-picker": "^0.41.1",
    "react-native-image-zoom-viewer": "^3.0.1",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-maps": "^1.15.6",
    "react-native-modal": "^13.0.1",
    "react-native-modal-datetime-picker": "^17.1.0",
    "react-native-permissions": "latest",
    "react-native-phone-number-input": "^2.1.0",
    "react-native-ratings": "^8.1.0",
    "react-native-reanimated": "^3.12.0",
    "react-native-reanimated-carousel": "^3.5.1",
    "react-native-safe-area-context": "^4.10.4",
    "react-native-screens": "^3.31.1",
    "react-native-vector-icons": "^10.1.0",
    "react-redux": "^9.1.2",
    "yup": "^1.4.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.74.84",
    "@react-native/eslint-config": "0.74.84",
    "@react-native/metro-config": "0.74.84",
    "@react-native/typescript-config": "0.74.84",
    "@types/react": "^18.2.6",
    "@types/react-native-vector-icons": "^6.4.18",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  },
  "packageManager": "yarn@3.6.4"
}

已尝试的解决步骤

  • 执行pod install --repo-update更新依赖
  • 删除Pods和Podfile.lock后重新执行pod install
  • 在Xcode中清理构建文件夹
  • 删除/Users/Library/Developer/Xcode/DerivedData目录内容

解决方案建议

  1. 手动添加GoogleSignIn Pod依赖
    在Podfile的target 'OfferBoat' do代码块内,添加与@react-native-google-signin/google-signin v12.2.1兼容的GoogleSignIn Pod声明(对应7.x版本):

    pod 'GoogleSignIn', '~> 7.0', :modular_headers => true
    

    保存后重新执行pod install --repo-update。

  2. 调整静态框架配置
    由于项目启用了静态框架链接,确保GoogleSignIn以静态方式引入,可修改Podfile中的声明为:

    pod 'GoogleSignIn', '~> 7.0', :linkage => :static
    
  3. 验证自动链接有效性
    执行npx react-native config,查看输出中@react-native-google-signin/google-signin的iOS配置是否包含正确的Pod引用,若缺失则需手动添加上述依赖。

  4. 清理全量缓存后重装
    执行以下命令彻底清理缓存并重新安装依赖:

    yarn cache clean
    rm -rf node_modules
    yarn install
    cd ios
    rm -rf Pods Podfile.lock
    pod install --repo-update
    
  5. 检查Xcode构建配置
    打开Xcode项目,进入Build Settings:

    • 找到Framework Search Paths,添加$(PROJECT_DIR)/Pods/GoogleSignIn并勾选「Recursive」
    • 确认Other Linker Flags中包含-framework GoogleSignIn
  6. 确认版本兼容性
    避免版本冲突,确保@react-native-google-signin/google-signin与GoogleSignIn Pod版本匹配:v12.x对应GoogleSignIn 7.x,v11.x对应GoogleSignIn 6.x。

内容的提问来源于stack exchange,提问作者Maria Noor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 23:00:53