集成FCM后iOS编译报错: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目录内容
解决方案建议
手动添加GoogleSignIn Pod依赖
在Podfile的target 'OfferBoat' do代码块内,添加与@react-native-google-signin/google-signinv12.2.1兼容的GoogleSignIn Pod声明(对应7.x版本):pod 'GoogleSignIn', '~> 7.0', :modular_headers => true保存后重新执行
pod install --repo-update。调整静态框架配置
由于项目启用了静态框架链接,确保GoogleSignIn以静态方式引入,可修改Podfile中的声明为:pod 'GoogleSignIn', '~> 7.0', :linkage => :static验证自动链接有效性
执行npx react-native config,查看输出中@react-native-google-signin/google-signin的iOS配置是否包含正确的Pod引用,若缺失则需手动添加上述依赖。清理全量缓存后重装
执行以下命令彻底清理缓存并重新安装依赖:yarn cache clean rm -rf node_modules yarn install cd ios rm -rf Pods Podfile.lock pod install --repo-update检查Xcode构建配置
打开Xcode项目,进入Build Settings:- 找到
Framework Search Paths,添加$(PROJECT_DIR)/Pods/GoogleSignIn并勾选「Recursive」 - 确认
Other Linker Flags中包含-framework GoogleSignIn
- 找到
确认版本兼容性
避免版本冲突,确保@react-native-google-signin/google-signin与GoogleSignIn Pod版本匹配:v12.x对应GoogleSignIn 7.x,v11.x对应GoogleSignIn 6.x。
内容的提问来源于stack exchange,提问作者Maria Noor

