ruby 升级到react-native 0.72.6后,Podfile错误`undefined local variable or method config`

pepwfjgg  于 8个月前  发布在  Ruby
关注(0)|答案(1)|浏览(317)

React Native从0.69.6升级到0.72.6
我正在使用升级帮助工具:https://react-native-community.github.io/upgrade-helper/?from=0.69.6&to=0.72.6
在运行pod install时在Podfile中添加更改后,我得到:

undefined local variable or method `config' for #<Pod::Podfile:0x00007fd4af859360>

<projectPath>/ios/Podfile:109:in `block (2 levels) in from_ruby'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-core-1.11.3/lib/cocoapods-core/podfile.rb:196:in `post_install!'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:945:in `run_podfile_post_install_hook'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:933:in `block in run_podfile_post_install_hooks'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:149:in `message'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:932:in `run_podfile_post_install_hooks'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:331:in `block (2 levels) in create_and_save_projects'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pods_project_writer.rb:61:in `write!'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:330:in `block in create_and_save_projects'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:64:in `section'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:309:in `create_and_save_projects'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:301:in `generate_pods_project'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:180:in `integrate'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:167:in `install!'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/command/install.rb:52:in `run'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in `run'
<userPath>/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/cocoapods-1.11.3/bin/pod:55:in `<top (required)>'
<userPath>/.rbenv/versions/2.7.5/bin/pod:23:in `load'
<userPath>/.rbenv/versions/2.7.5/bin/pod:23:in `<main>'

字符串
我的Podfile看起来像这样:

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip
platform :ios, min_ios_version_supported
prepare_react_native_project!

flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled
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

install! 'cocoapods', :deterministic_uuids => false
use_frameworks! :linkage => :static
inhibit_all_warnings!

# Turn off the ad id support for firebase analytics because the app is meant to
# be used by kids. See related error below as to why we need this:
# FastlaneCore::Interface::FastlaneShellError: [!] RNFBAnalytics: Using default
# Firebase/Analytics with Ad Ids. May require App Tracking Transparency.
# Not allowed for Kids apps.
$RNFirebaseAnalyticsWithoutAdIdSupport = true

source 'https://cdn.cocoapods.org/'

target 'WonderPushNotificationServiceExtension' do
  platform :ios, '10.0'

  # Pods for WonderPushNotificationServiceExtension
  pod 'WonderPushExtension', '~> 4.0'
end

# Avoid duplicate symbols:
$dynamic_library = ['StreamAMGSDK/PlayKit', 'YouboraLib']
pre_install do |installer|
  Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
  installer.pod_targets.each do |pod|
    bt = pod.send(:build_type)
    if $dynamic_library.include?(pod.name)
      puts "** #{pod.name} left as dynamic **"
    else
      puts "#{pod.name} static_library"
      def pod.build_type;
      Pod::BuildType.static_library
    end
  end
end
end

target 'MyProjectName' do
 # Flags change depending on the env values.
  flags = get_default_flags()
  permissions_path = '../node_modules/react-native-permissions/ios'
  config = use_native_modules!
  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => true,
    :fabric_enabled => flags[:fabric_enabled],
    #  :flipper_configuration => FlipperConfiguration.enabled,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  pod 'SwiftLint'
  pod 'GoogleAds-IMA-iOS-SDK', '~> 3.18.1'
  pod 'StreamAMGSDK/PlayKit', '1.3.0'
  pod 'XCGLogger', :modular_headers => true
  pod 'ObjcExceptionBridging', :modular_headers => true
  pod 'react-native-google-cast/NoBluetooth', path: '../node_modules/react-native-google-cast/'
  pod 'google-cast-sdk-no-bluetooth'
  pod 'DailymotionPlayerSDK', '4.0.4'

  pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"

  pod 'Firebase', '~> 10.17.0', :modular_headers => true
  pod 'FirebaseCore', '~> 10.17.0', :modular_headers => true
  pod 'FirebaseCoreInternal', '~> 10.17.0', :modular_headers => true
  pod 'FirebaseCoreExtension', '~> 10.17.0', :modular_headers => true
  pod 'FirebaseInstallations', '~> 10.17.0', :modular_headers => true
  pod 'Firebase/Performance', '~> 10.17.0', :modular_headers => true
  pod 'Firebase/Crashlytics', '~> 10.17.0', :modular_headers => true
  pod 'Firebase/DynamicLinks', '~> 10.17.0', :modular_headers => true
  pod 'FirebaseABTesting', :modular_headers => true
  pod 'FirebaseRemoteConfig', :modular_headers => true
  pod 'GoogleDataTransport', :modular_headers => true
  pod 'nanopb', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true

end

post_install do |installer|
  # config = use_native_modules! <---- re-adding this fixes the issue but is it OK??
  flipper_post_install(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
    )
  __apply_Xcode_12_5_M1_post_install_workaround(installer)

  # older fixes, not sure if they are still needed in RN 0.72.6:

  installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
  end

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.0'
    end
  end

  installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
              config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
            end
          end

  # https://github.com/CocoaPods/CocoaPods/issues/11402#issuecomment-1201464693
  installer.pods_project.targets.each do |target|
    if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle"
      target.build_configurations.each do |config|
          config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
      end
    end
  end
end


我在这里找到了这个答案,但我不知道如何将它适应我的Podfile内容:
https://github.com/facebook/react-native/issues/38087
我需要在我的Podfile中添加什么更改来修复undefined local variable or method config错误?

qoefvg9y

qoefvg9y1#

我找到了两个解决问题的方法:
1.在post_install块中重新添加config = use_native_modules!,第一行
1.使用来自react-native站点的演示Podfile并在目标块中添加post_install块:

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

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

target 'HelloWorld' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'HelloWorldTests' 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
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

字符串
资料来源:
https://github.com/facebook/react-native/blob/0.72-stable/packages/react-native/template/ios/Podfile
https://github.com/facebook/react-native/issues/38067#issuecomment-1766411375

相关问题