'flutter error Invalid `Podfile` file: no implicit conversion of nil into String. ive searched through discussions but I cant seem to fix the issue
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
Solution 1:[1]
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
Solution 2:[2]
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!!!
Solution 3:[3]
I was in channel beta and I solved like this. flutter channel stable and flutter upgrade
Solution 4:[4]
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
Solution 5:[5]
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.
Solution 6:[6]
I solve it just replace: copied_flutter_dir = File.join(__dir__, 'Flutter') to copied_flutter_dir = File.join('.', 'Flutter').
Solution 7:[7]
The root cause of this error most of the times happens after you have cloned a project like from Github.
In order to fix it, you need to get the packages and install the pods.
flutter clean && flutter pub get && cd ios/ && pod install
And update your Pod Repo and Pods
pod repo update && pod update
Solution 8:[8]
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
Solution 9:[9]
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 channelto see the active channel, then switch to stable if its selected beta by running the commandflutter 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
- run
flutter clean - run
cd iosin 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 iosbetter use--verboseto see if any other issues are there.
Hope this will help if anyone stuck at the same problem. thanks to these guys.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vishnu Haridas |
| Solution 2 | |
| Solution 3 | Aytug Sevgi |
| Solution 4 | Nicolas |
| Solution 5 | Emily |
| Solution 6 | sreng bona |
| Solution 7 | Paresh Mangukiya |
| Solution 8 | Ahmed Bayoumy |
| Solution 9 |
