Skip to content

pod install error NoMethodError - undefined method size' for nil:NilClass at macho_file.rb in populate_mach_header' #55903

@gaaclarke

Description

@gaaclarke

There is a lot of issues filed against CocoaPods from a situation that arises in Flutter for example: CocoaPods/CocoaPods#8377. They all have the following text:
NoMethodError - undefined method size' for nil:NilClass`

I tried the following things to fix the error:

  1. flutter upgrade; flutter clean; flutter run
  2. delete ios/Pods folder
  3. gem update ruby-macho
  4. sudo gem install cocoapods

The only thing that worked to fix the issue was git clean -fX to delete all untracked files. There is something that is messing up CocoaPods that should get flushed with flutter clean.

Seen on latest stable and master (1.18.0-9.0.pre.46)

Full Log
aaclarke-macbookpro2:example aaclarke$ flutter run
Launching lib/main.dart on iPhone (2) in debug mode...
Warning: Missing build name (CFBundleShortVersionString).
Warning: Missing build number (CFBundleVersion).
Action Required: You must set a build name and number in the pubspec.yaml file version field before submitting to the
App Store.
Automatically signing iOS for device deployment using specified development team in Xcode project: S8QB4VV633
Running pod install...                                              1.6s
CocoaPods' output:
↳
      Preparing

    Analyzing dependencies

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

    Finding Podfile changes
      - Flutter
      - e2e
      - video_player
      - video_player_web

    Fetching external sources
    -> Fetching podspec for `Flutter` from `Flutter`
    -> Fetching podspec for `e2e` from `.symlinks/plugins/e2e/ios`
    -> Fetching podspec for `video_player` from `.symlinks/plugins/video_player/ios`
    -> Fetching podspec for `video_player_web` from `.symlinks/plugins/video_player_web/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 e2e
      A video_player
      A video_player_web

    Downloading dependencies

    -> Installing Flutter (1.0.0)

    -> Installing e2e (0.0.1)

    -> Installing video_player (0.0.1)

    -> Installing video_player_web (0.0.1)
      - Running pre install hooks

    Generating Pods project
      - Creating Pods project
      - Installing files into Pods project
        - Adding source files
        - Adding frameworks
        - Adding libraries
        - Adding resources
        - Adding development pod helper files
        - Linking headers
      - Installing Pod Targets
        - Installing target `Flutter` iOS 8.0
        - Installing target `e2e` iOS 8.0
          - Generating module map file at `Pods/Target Support Files/e2e/e2e.modulemap`
          - Generating umbrella header at `Pods/Target Support Files/e2e/e2e-umbrella.h`
          - Generating dummy source at `Pods/Target Support Files/e2e/e2e-dummy.m`
        - Installing target `video_player` iOS 8.0
          - Generating module map file at `Pods/Target Support Files/video_player/video_player.modulemap`
          - Generating umbrella header at `Pods/Target Support Files/video_player/video_player-umbrella.h`
          - Generating dummy source at `Pods/Target Support Files/video_player/video_player-dummy.m`
        - Installing target `video_player_web` iOS 8.0
      - Installing Aggregate Targets
        - Installing target `Pods-Runner` iOS 8.0
      CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only perfomed in repo
      update

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

    ### Command

    ```
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/bin/pod install --verbose
    ```

    ### Report

    * What did you do?

    * What did you expect to happen?

    * What happened instead?


    ### Stack

    ```
       CocoaPods : 1.8.3
            Ruby : ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
        RubyGems : 2.5.2.3
            Host : Mac OS X 10.14.6 (18G2022)
           Xcode : 11.3 (11C29)
             Git : git version 2.26.0.110.g2183baf09c-goog
    Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib
    Repositories : master - git - https://github.com/CocoaPods/Specs.git @ e7f31f463f3333f320be4de3f5734141bb3d8921
                   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.4.1
    cocoapods-try         : 1.1.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
      # 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
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho/macho_file.rb:455:in `populate_mach_header'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho/macho_file.rb:233:in `populate_fields'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho/macho_file.rb:55:in `initialize_from_bin'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho/macho_file.rb:33:in `new_from_bin'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho/fat_file.rb:365:in `block in populate_machos'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho/fat_file.rb:364:in `each'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho/fat_file.rb:364:in `populate_machos'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho/fat_file.rb:156:in `populate_fields'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho/fat_file.rb:95:in `initialize'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho.rb:31:in `new'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/ruby-macho-1.4.0/lib/macho.rb:31:in `open'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/sandbox/file_accessor.rb:457:in
    `dynamic_binary?'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/sandbox/file_accessor.rb:171:in `block in
    vendored_dynamic_frameworks'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/sandbox/file_accessor.rb:170:in `select'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/sandbox/file_accessor.rb:170:in
    `vendored_dynamic_frameworks'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/sandbox/file_accessor.rb:259:in
    `vendored_dynamic_artifacts'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:1123:in `block (3
    levels) in <class:AggregateTargetSettings>'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:1122:in `any?'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:1122:in `block (2
    levels) in <class:AggregateTargetSettings>'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:1121:in `any?'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:1121:in `block in
    <class:AggregateTargetSettings>'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:114:in `block in
    define_build_settings_method'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:1113:in `block in
    <class:AggregateTargetSettings>'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:114:in `block in
    define_build_settings_method'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:362:in
    `public_send'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:362:in `block in
    to_h'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:361:in `each'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:361:in `to_h'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:174:in `block in
    <class:BuildSettings>'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:970:in `block in
    <class:AggregateTargetSettings>'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:114:in `block in
    define_build_settings_method'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/target/build_settings.rb:190:in `save_as'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/pods_project_generator/targ
    et_installer_helper.rb:24:in `update_changed_file'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/pods_project_generator/aggr
    egate_target_installer.rb:102:in `block in create_xcconfig_file'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/pods_project_generator/aggr
    egate_target_installer.rb:98:in `each'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/pods_project_generator/aggr
    egate_target_installer.rb:98:in `create_xcconfig_file'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/pods_project_generator/aggr
    egate_target_installer.rb:18:in `block in install!'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/user_interface.rb:145:in `message'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/pods_project_generator/aggr
    egate_target_installer.rb:14:in `install!'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/pods_project_generator.rb:1
    30:in `block (2 levels) in install_aggregate_targets'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/pods_project_generator.rb:1
    28:in `map'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/pods_project_generator.rb:1
    28:in `block in install_aggregate_targets'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/user_interface.rb:145:in `message'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/pods_project_generator.rb:1
    27:in `install_aggregate_targets'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer/xcode/single_pods_project_generat
    or.rb:20:in `generate!'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer.rb:308:in `block in
    create_and_save_projects'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/user_interface.rb:64:in `section'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer.rb:303:in
    `create_and_save_projects'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer.rb:294:in `generate_pods_project'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer.rb:173:in `integrate'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/installer.rb:162:in `install!'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/command/install.rb:52:in `run'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/lib/cocoapods/command.rb:52:in `run'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/gems/cocoapods-1.8.3/bin/pod:55:in `<top (required)>'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/bin/pod:22:in `load'
    /Users/aaclarke/.rvm/gems/ruby-2.4.3/bin/pod:22: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/9484 [closed] [9 comments]
       2 weeks ago

     - pod install crashes
       https://github.com/CocoaPods/CocoaPods/issues/9654 [closed] [2 comments]
       4 weeks ago

     - NoMethodError - undefined method `size' for nil:NilClass
       https://github.com/CocoaPods/CocoaPods/issues/8377 [closed] [11 comments]
       17 Feb 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:
↳
    Ignoring eventmachine-1.2.7 because its extensions are not built.  Try: gem pristine eventmachine --version 1.2.7
    Ignoring executable-hooks-1.6.0 because its extensions are not built.  Try: gem pristine executable-hooks --version
    1.6.0
    Ignoring ffi-1.11.1 because its extensions are not built.  Try: gem pristine ffi --version 1.11.1
    Ignoring gem-wrappers-1.4.0 because its extensions are not built.  Try: gem pristine gem-wrappers --version 1.4.0
    Ignoring http_parser.rb-0.6.0 because its extensions are not built.  Try: gem pristine http_parser.rb --version
    0.6.0
    Ignoring nokogiri-1.10.4 because its extensions are not built.  Try: gem pristine nokogiri --version 1.10.4
    Ignoring sassc-2.2.0 because its extensions are not built.  Try: gem pristine sassc --version 2.2.0

    [!] 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`.

Error running pod install

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectplatform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions