Fixing "Invalid `Podfile` file: no implicit conversion of nil into String."

I tried running integration tests on a my project, and I got this cryptic error:

% flutter drive --target=test_driver/cloud_firestore_behaviors.dart
Running "flutter pub get" in cloud_firestore_mocks...            1,005ms
Running pod install...                                             653ms
CocoaPods' output:
↳

    [!] Invalid `Podfile` file: no implicit conversion of nil into String.

     #  from /Users/[username]/git/cloud_firestore_mocks/ios/Podfile:54
     #  -------------------------------------------
     #      unless File.exist?(copied_framework_path)
     >        FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
     #      end
     #  -------------------------------------------

    /Library/Ruby/Gems/2.6.0/gems/cocoapods-core-1.10.1/lib/cocoapods-core/podfile.rb:318:in `rescue in block in from_ruby'

Note that I haven't managed to fix it yet, but you can still read what I've tried.

Is it Ruby?

It used to work! Back when I was using another computer. The first post about the error I saw was this one: https://stackoverflow.com/questions/65516334/flutter-error-invalid-podfile-file-no-implicit-conversion-of-nil-into-string. They recommend doing anything and everything.

After searching a bit more, I found https://github.com/flutter/flutter/issues/54675, which seems to be handled by better informed people. They mention a fix (update Ruby) and a workaround (replace __dir__ by .).

This is the ruby version I have:

% ruby -version 
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.arm64e-darwin20]

Over at https://www.ruby-lang.org/en/downloads/, they mention two ways of installing Ruby on Mac OS, rbenv and RVM, none of which I have ever heard of. Funny how rbenv's README has a section entitled "Why choose rbenv over RVM?" in bold letter.

Searching some more about Ruby 2.7 for M1, I found:

The last post states:

I just cannot recommend this approach at this moment until things get ironed out. There are still too many issues and compatibility problems with the Ruby ARM Version. I've found a few crashes and it's just not stable enough. For now, continue to use the Ruby x86 version.

I'll dig into the details of the posts later, in order to see how easy I can install it. Seems like the poster was at least able to install the x86 version using RVM.

Is it my generated config file?

Just to see if I could do a quick fix, just to run my integration tests, I replaced __dir__ by . like the post suggested. It still failed. Looking at the code more closely, it looks like the null value comes from:

generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];

In this file, there is a FLUTTER_ROOT key/value, but none called FLUTTER_FRAMEWORK_DIR. So is the Podfile out of date, or is the Generated.xcconfig out of date?

I'll have to investigate later.