31

This is the error I am receiving. I tried flutter clean and changing the syntax of some lines but im new to dart and flutter so im not really sure. I reinstalled cocoa pods and ruby as well but Im receiving the same error. I also made sure to update ruby to the latest version.

  [!] Invalid `Podfile` file: no implicit conversion of nil into String.
         #  from /Users/(name)/Downloads/Projects/doctor_consultation_app/ios/Podfile:57
         #  -------------------------------------------
         #      unless File.exist?(copied_framework_path)
         >        FileUtils.cp(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
         #      end
         #  -------------------------------------------

This is my pod file.

# 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

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
ch271828n
  • 15,854
  • 5
  • 53
  • 88
aarushi
  • 357
  • 1
  • 4
  • 5

8 Answers8

48

I got this error when I updated my flutter sdk to the new flutter 2.0, but my project was created with older version of flutter sdk (1.22).

Fixed It by deleting the Podfile and Podfile.lock in ios folder and then run:

flutter run

or

flutter build ios

That way flutter will generate the new Podfile for flutter 2.0

Vishnu Haridas
  • 7,355
  • 3
  • 28
  • 43
TatkoBarba
  • 1,047
  • 8
  • 7
9

I have same problem when I update my mac --> BigSur and use Ruby .

And I solve it by rm -rf ios and flutter create .

Then fix some file changes in new ios

Warning!!!

if use this on your existing app, it will deleted your iOS folder, but You may have some custom settings in it. So you should add your commit into the new file!!!

植植心
  • 406
  • 3
  • 5
  • 3
    Don't use this on your existing app, This deleted my iOS folder and flutter create command will create a new project. Thankfully I use git and could reset to my commit. – Jaswant Singh Mar 02 '21 at 08:05
  • 1
    You should add "Warning" test in your solution for existing applications – Levent KANTAROGLU Mar 24 '21 at 08:49
  • You'd need to set the project path on the script, you can also specify the paltform that you'll create i.e. `flutter create --platforms=ios [PROJECT_PATH]`. Replace [PROJECT_PATH] with the actual path of the Flutter project. – Omatt Sep 08 '21 at 15:42
2

I was in channel beta and I solved like this. flutter channel stable and flutter upgrade

2

The Pod file can change depending on the channel you are using. Try to update flutter

flutter channel stable
flutter upgrade

Delete your pod file and the Pods folder then rebuild your ios project

flutter build ios
Nicolas
  • 663
  • 6
  • 17
2

I had to delete the podfile and add it back, then add my extensions back in. Now it seems to be working again. Most of the file got stripped, for example the new file has no parse_KV_file method.

Emily
  • 21
  • 3
0

I solve it just replace: copied_flutter_dir = File.join(__dir__, 'Flutter') to copied_flutter_dir = File.join('.', 'Flutter').

sreng bona
  • 303
  • 5
  • 14
0

Just sharing my experience with this type of issue, it looks like its basically a versioning issue of pods. I've worked in several hybrid platforms, and it turns out all of the platforms are struggling when comes to build for iOS. Here's how I resolved it:

  • I've checked my flutter channel whether it's beta or stable, I found it was beta so I switched into the stable channel. commands are flutter channel to see the active channel, then switch to stable if its selected beta by running the command flutter channel stable
  • remove all generated pod/related files for a fresh build. do the following:
    • run rm -rf ios/Pods
    • run rm -rf ios/.symlinks
    • run rm -rf ios/Flutter/Flutter.framework
  • run flutter clean
  • run cd ios in case you're not in the ios folder.
  • run pod cache clean --all
  • run pod repo update
  • run pod install
  • uncomment platform :ios, 'X.0' from Podfile inside ios folder, and replace X with the current version you're woking.
  • run flutter build ios better use --verbose to see if any other issues are there.

Hope this will help if anyone stuck at the same problem. thanks to these guys.

https://stackoverflow.com/a/64318163/3502024

https://stackoverflow.com/a/65539806/3502024

noman404
  • 928
  • 1
  • 8
  • 23
  • 3
    Getting this mess, too. I've done NOTHING to this code tree in a couple of months, and now this. I swear, this platform just gets more and more fragile every day. I had to basically do ALL of this crap, all the suggestions, to get it to work and I'm still getting new runtime errors that were previously gone (the threading thing that people keep reporting). All I wanted to do was install it on another phone I had here. No code or dependency changes. Worked fine last time I was in here. I can't keep supporting this platform like this. – ChrisH Feb 25 '21 at 16:52
0

pls make sure to remove to .dart_tool folder from the root of the project,

Then inside the ios folder, try flutter clean and flutter build ios