繁体   English   中英

来源:将 Cocoapods 用于 Firebase 时未绑定变量错误

[英]source: unbound variable error when using Cocoapods for Firebase

我已经使用 Cocoapods 将FirebaseGoogleTagManager集成到我的 iOS 应用程序目标中。 当我构建目标时,Xcode 不断给我错误:


Showing Recent Messages
PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks 

mkdir -p /Users/xxx.xxx/Library/Developer/Xcode/DerivedData/MyApp-enzvpdzsyhjszqbnwiclnpszlyri/Build/Products/Debug-iphonesimulator/MyApp.app/Frameworks


/Users/xxx.xxx/Projects/MyApp/Applications/MyApp/Pods/Target Support Files/Pods-MyApp/Pods-MyApp-frameworks.sh: line 43: source: unbound variable


Command /bin/sh failed with exit code 1

我已经多次清理我的项目,删除了派生数据文件夹,但这些似乎都不起作用。

我的 Podfile 看起来像这样:

platform :ios, '11.0'

target 'MyApp' do

  use_frameworks!

  # Pods for MyApp
    pod 'Firebase/Core', '~> 5.19'
    pod 'Firebase/ABTesting'
    pod 'Firebase/Performance'
    pod 'Firebase/RemoteConfig'
    pod 'Firebase/Analytics'
    pod 'GoogleTagManager', '~> 7.1'
 end

可可豆环境

CocoaPods : 1.5.3
        Ruby : ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
    RubyGems : 2.6.8
        Host : Mac OS X 10.14 (18A391)
       Xcode : 10.1 (10B61)
         Git : git version 2.17.2 (Apple Git-113)
Ruby lib dir : /Users/xxx.xxx/.rbenv/versions/2.4.0/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 7c9a708dce25221eabc35ed39

我的项目设置中缺少什么导致此错误的原因?

我花了几天时间寻找关于 SO / Cocoapods 的解决方案,但徒劳无功。

在这方面的任何帮助将不胜感激。

谢谢

这似乎是一些特殊的问题,也许与 bash 相关或其他什么。 由于某些奇怪的原因,它不适用于 ~/Library/.../MyApp-xxxxx.../Build/Products/Release-iphoneos/ 目录(我们称之为 BUILD_DIR)

如果 'source' 未定义,这里就是这种情况,用 ${source:-} 替换 ${source} 没有帮助,因为这样它会为源放置一个空白,这不是你想要的。

对我来说,另一个问题是 rsync 找不到上述目录。

这是我所做的:

  1. 让项目构建并给出错误。 这确保在我的 BUILD_DIR 中创建所需的框架目录,并构建框架。

  2. 在项目根目录下创建目录Pods-frameworks,将BUILD_DIR中所有framework目录复制到该目录下。

  3. 在 PodsMyApp-frameworks.sh 中,最后 25 行,在调试和发布模式下调用 install_framework 与所有与 Pods 相关的框架,将 ${BUILT_PRODUCTS_DIR} 更改为一个新的宏,该宏定义为这个新的 Pods-frameworks 目录。

  4. 再次构建项目。

那解决了问题。 如果再次安装 pods 并且版本发生更改,则可能需要重复此过程。

好吧,我已经把这个问题弄乱了 4 天,最后用脚本解决了。

设置

  • RN 0.61.50.59.10升级
  • Xcode 11.3.1
    • 多方案(Staging,Beta)
    • 多配置(Staging,Beta)
  • 可可豆1.9.3

相关的 npm 包:

    "react-native": "0.61.5",
    "@react-native-firebase/app": "^8.4.6",
    "@react-native-firebase/auth": "^9.3.1",
    "@react-native-firebase/crashlytics": "^8.4.11",
    "@react-native-firebase/database": "^7.5.12",
    "@react-native-firebase/messaging": "^7.9.1",
    "react-native-code-push": "6.3.0",
    "react-native-config": "1.4.0"

使用的指南和来源:

播客文件:

platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

project 'lend24app',
  'Debug' => :debug,
  'Release' => :release,
  'Staging' => :release,
  'Beta' => :release


target 'lend24app' do
  use_frameworks!
  $RNFirebaseAsStaticFramework = true

  # Pods for lendmn
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  pod 'RNInputMask', :path => '../node_modules/react-native-text-input-mask/ios/InputMask'
  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'

  permissions_path = '../node_modules/react-native-permissions/ios'

  pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
  pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts.podspec"
  pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID.podspec"
  pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways.podspec"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse.podspec"
  pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary.podspec"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications.podspec"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary.podspec"
  pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders.podspec"
  pod 'Permission-StoreKit', :path => "#{permissions_path}/StoreKit.podspec"


  pre_install do |installer|
    installer.analysis_result.specifications.each do |s|
      s.swift_version = '4.0' unless s.swift_version
    end
    # workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}

    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
        def pod.build_type;
          # Uncomment one line depending on your CocoaPods version
          Pod::BuildType.static_library # >= 1.9
        end
      end
    end
  end

  post_install do |installer|
    installer.pods_project.build_configurations.each do |config|
      if config.name == 'Staging' || config.name == 'Beta'
        config.build_settings['CONFIGURATION_TEMP_DIR'] = '$(PROJECT_TEMP_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)'
        config.build_settings['CONFIGURATION_BUILD_DIR'] = '$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)'
      end
    end
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        if config.name == 'Staging' || config.name == 'Beta'
          config.build_settings['CONFIGURATION_TEMP_DIR'] = '$(PROJECT_TEMP_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)'
          config.build_settings['PODS_CONFIGURATION_BUILD_DIR'] = '${PODS_BUILD_DIR}/Release$(EFFECTIVE_PLATFORM_NAME)'
        end
      end
    end
  end

  target 'lend24appTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

这个设置是2016年以来一个项目逐步发展的结果,所以不推荐项目和实际配置,最好从头开始!

导致此问题的步骤,所有步骤均无法生成 beta 存档:

  1. 通过升级命令升级rn
  2. 使用RN Upgrade helper修补通过命令丢失的文件
  3. 使用上面提到的 Code Push 指南创建 Xcode 配置
  4. 未知...

在旅途中的某个地方,我最终得到了PODS_CONFIGURATION_BUILD_DIR构建设置,其中包含用于 Beta configuration ${PODS_BUILD_DIR}/Release$(EFFECTIVE_PLATFORM_NAME)

此时正在运行Beta构建,但归档失败, source: unbound variable

每当我将PODS_CONFIGURATION_BUILD_DIR更改为${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)或者如果我编辑出相同PODS_CONFIGURATION_BUILD_DIRPodfile修复程序更改构建阶段失败

'React/RCTBridgeDelegate.h' file not found.

挖掘...frameworks.sh很明显,由于PODS_CONFIGURATION_BUILD_DIR设置或类似设置,Pods 构建输出到Release-iphoneos文件夹,而其余部分在Beta-iphoneos ,我尝试更改为默认值,但随后构建甚至在达到此构建阶段之前就失败了[CP] Embed Pods Frameworks

最后,在此阶段之前,我使用以下脚本将所有内容从Release-iphoneosBeta-iphoneos

+ New Run Script Phase

# Type a script or drag a script file from your workspace to insert its path.
if [[ "$CONFIGURATION" == "Debug" ]]; then
    exit 0
elif [[ "$CONFIGURATION" == "Release" ]]; then
    exit 0
fi

mv $BUILD_DIR/Release$EFFECTIVE_PLATFORM_NAME/* $BUILD_DIR/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME/

在这里有点累,只是认为它可以帮助任何类似情况的人,希望我能提供更多帮助,欢迎反馈。

当我的框架是用 M1 芯片构建时,我遇到了同样的问题。 我能够通过从 Podfile 安装程序部分中删除 ONLY_ACTIVE_ARCH 来解决这个问题。

所以我替换了这个:

post_install do |installer|

installer.pods_project.targets.each do |target|

target.build_configurations.each do |config|
  config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
  config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'

 end
end

有了这个:

post_install do |installer|

installer.pods_project.targets.each do |target|

target.build_configurations.each do |config|
  config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
 end
end

注意:当框架是用非 M1 芯片构建时,我从一开始就添加了 ['ONLY_ACTIVE_ARCH'] = 'NO' 以便在模拟器中使用“有问题的”框架运行我的应用程序。 所以我仍然需要这条线,这取决于构建机器的芯片。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM