首页 > 解决方案 > 无法在颤振中添加包(仅在 mac 上)

问题描述

我成功地在我的 iOS 设备上运行了基本的颤振示例。我有最后一个 Xcode 和 catalina。但是每次我尝试添加包时,我都会遇到这样的问题:

Running pod install...
CocoaPods' output:
↳
      Preparing

    Analyzing dependencies

    Inspecting targets to integrate
      Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)

    Fetching external sources
    -> Fetching podspec for `Flutter` from `Flutter`
    -> Fetching podspec for `screenshot_share_image` from `.symlinks/plugins/screenshot_share_image/ios`

    Resolving dependencies of `Podfile`
      CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only perfomed in repo update

    Comparing resolved specification to the sandbox manifest
      A Flutter
      A screenshot_share_image

    Downloading dependencies

    -> Installing Flutter (1.0.0)

    -> Installing screenshot_share_image (0.0.1)
      - Running pre install hooks
      CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only perfomed in repo update

    ――― MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

    ### Command

    ```
    /usr/local/bin/pod install --verbose
    ```

    ### Report

    * What did you do?

    * What did you expect to happen?

    * What happened instead?


    ### Stack

    ```
       CocoaPods : 1.9.3
            Ruby : ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
        RubyGems : 3.0.3
            Host : Mac OS X 10.15.5 (19F101)
           Xcode : 11.5 (11E608c)
             Git : git version 2.24.3 (Apple Git-128)
    Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib
    Repositories : master - git - https://github.com/CocoaPods/Specs.git @ 1e10b07eb1af53011a1e344b101c47327c5f8b62

                   trunk - CDN - https://cdn.cocoapods.org/
    ```

    ### Plugins

    ```
    cocoapods-deintegrate : 1.0.4
    cocoapods-plugins     : 1.0.0
    cocoapods-search      : 1.0.0
    cocoapods-stats       : 1.1.0
    cocoapods-trunk       : 1.5.0
    cocoapods-try         : 1.2.0
    ```

    ### Podfile

    ```ruby
    # Uncomment this line to define a global platform for your project
    # platform :ios, '9.0'

    # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
    ENV['COCOAPODS_DISABLE_STATS'] = 'true'

    project 'Runner', {
      'Debug' => :debug,
      'Profile' => :release,
      'Release' => :release,
    }

    def parse_KV_file(file, separator='=')
      file_abs_path = File.expand_path(file)
      if !File.exists? file_abs_path
        return [];
      end
      generated_key_values = {}
      skip_line_start_symbols = ["#", "/"]
      File.foreach(file_abs_path) do |line|
        next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
        plugin = line.split(pattern=separator)
        if plugin.length == 2
          podname = plugin[0].strip()
          path = plugin[1].strip()
          podpath = File.expand_path("#{path}", file_abs_path)
          generated_key_values[podname] = podpath
        else
          puts "Invalid plugin specification: #{line}"
        end
      end
      generated_key_values
    end

    target 'Runner' do
      use_frameworks!
      use_modular_headers!

      # Flutter Pod

      copied_flutter_dir = File.join(__dir__, 'Flutter')
      copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
      copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
      unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
        # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
        # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
        # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.

        generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
        unless File.exist?(generated_xcode_build_settings_path)
          raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
        end
        generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
        cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];

        unless File.exist?(copied_framework_path)
          FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
        end
        unless File.exist?(copied_podspec_path)
          FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
        end
      end

      # Keep pod path relative so it can be checked into Podfile.lock.
      pod 'Flutter', :path => 'Flutter'

      # Plugin Pods

      # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
      # referring to absolute paths on developers' machines.
      system('rm -rf .symlinks')
      system('mkdir -p .symlinks/plugins')
      plugin_pods = parse_KV_file('../.flutter-plugins')
      plugin_pods.each do |name, path|
        symlink = File.join('.symlinks', 'plugins', name)
        File.symlink(path, symlink)
        pod name, :path => File.join(symlink, 'ios')
      end
    end

    # Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
    install! 'cocoapods', :disable_input_output_paths => true

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['ENABLE_BITCODE'] = 'NO'
        end
      end
    end
    ```

    ### Error

    ```
    NoMethodError - undefined method `size' for nil:NilClass
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho/macho_file.rb:455:in `populate_mach_header'
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho/macho_file.rb:233:in `populate_fields'
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho/macho_file.rb:55:in `initialize_from_bin'
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho/macho_file.rb:33:in `new_from_bin'
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho/fat_file.rb:365:in `block in populate_machos'
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho/fat_file.rb:364:in `each'
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho/fat_file.rb:364:in `populate_machos'
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho/fat_file.rb:156:in `populate_fields'
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho/fat_file.rb:95:in `initialize'
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho.rb:31:in `new'
    /Library/Ruby/Gems/2.6.0/gems/ruby-macho-1.4.0/lib/macho.rb:31:in `open'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/xcode/linkage_analyzer.rb:16:in `dynamic_binary?'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/sandbox/file_accessor.rb:171:in `block in vendored_dynamic_frameworks'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/sandbox/file_accessor.rb:170:in `select'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/sandbox/file_accessor.rb:170:in `vendored_dynamic_frameworks'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/sandbox/file_accessor.rb:179:in `vendored_static_frameworks'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/sandbox/file_accessor.rb:292:in `vendored_static_artifacts'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/installer/xcode/target_validator.rb:82:in `each'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/installer/xcode/target_validator.rb:82:in `flat_map'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/installer/xcode/target_validator.rb:82:in `block (2 levels) in verify_no_static_framework_transitive_dependencies'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/installer/xcode/target_validator.rb:74:in `each_key'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/installer/xcode/target_validator.rb:74:in `block in verify_no_static_framework_transitive_dependencies'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/installer/xcode/target_validator.rb:73:in `each'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/installer/xcode/target_validator.rb:73:in `verify_no_static_framework_transitive_dependencies'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/installer/xcode/target_validator.rb:38:in `validate!'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/installer.rb:590:in `validate_targets'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/installer.rb:158:in `install!'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/command/install.rb:52:in `run'
    /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/lib/cocoapods/command.rb:52:in `run'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.9.3/bin/pod:55:in `<top (required)>'
    /usr/local/bin/pod:23:in `load'
    /usr/local/bin/pod:23:in `<main>'
    ```

    ――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

    [!] Oh no, an error occurred.

    Search for existing GitHub issues similar to yours:
    https://github.com/CocoaPods/CocoaPods/search?q=undefined+method+%60size%27+for+nil%3ANilClass&type=Issues

    If none exists, create a ticket, with the template displayed above, on:
    https://github.com/CocoaPods/CocoaPods/issues/new

    Be sure to first read the contributing guide for details on how to properly submit a ticket:
    https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md

    Don't forget to anonymize any private data!

    Looking for related issues on cocoapods/cocoapods...
     - NoMethodError - undefined method `size' for nil:NilClass
       https://github.com/CocoaPods/CocoaPods/issues/8377 [closed] [14 comments]
       a day ago

     - NoMethodError - undefined method `each' for nil:NilClass
       https://github.com/CocoaPods/CocoaPods/issues/9239 [closed] [5 comments]
       a week ago

     - NoMethodError - undefined method `size' for nil:NilClass
       https://github.com/CocoaPods/CocoaPods/issues/9484 [closed] [9 comments]
       14 Apr 2020

    and 4 more at:
    https://github.com/cocoapods/cocoapods/search?q=undefined%20method%20%60size%27%20for%20nil&type=Issues&utf8=✓

Error output from CocoaPods:
↳
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin19/rbconfig.rb:229: warning: Insecure world writable dir /Users/quentinguichot/Developer/flutter/bin in PATH, mode 040777

    [!] Automatically assigning platform `iOS` with version `8.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

Finished with error: Error running pod install

标签: flutter

解决方案


要解决此问题,请在终端中运行以下命令

flutter clean
rm -Rf ios/Pods
rm -Rf ios/.symlinks
rm -Rf ios/Flutter/Flutter.framework
rm -Rf ios/Flutter/Flutter.podspec

推荐阅读