Skip to content

🐛 [cloud_firestore][documentation] Example macOS Podfile is not up-to-date #7468

Closed
@Jonas-Sander

Description

@Jonas-Sander

Bug report

Much of the stuff that is inside the example Podfile isn't there when creating a new Podfile in a new macOS flutter project.

Especially since this was linked in the issues regarding build time (couldn't find the exact link again, but I know it was linked) it is not great when it is not up-to-date as bugs may arise and one doesn't know what you need to copy to your own Podfile.

Related #7467 (as the Podfile should probably updated when adding the documentation)

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a new flutter project
  2. Add cloud_firestore to pubspec.yaml
  3. Run flutter pub get
  4. Look at macos/Podfile

Expected behavior

The Podfile in the example project should be up-to-date.

Sample project

This is how a new Podfile with the current Flutter stable 2.5.3 looks:

platform :osx, '10.11'

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

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

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_macos_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_macos_build_settings(target)
  end
end

This is how the example Podfile looks:

platform :osx, '10.12'

require 'yaml'

pubspec = YAML.load_file(File.join('..', File.join('..', 'pubspec.yaml')))

# 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
  pods_ary = []
  skip_line_start_symbols = ["#", "/"]
  File.foreach(file_abs_path) { |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)
        pods_ary.push({:name => podname, :path => podpath});
      else
        puts "Invalid plugin specification: #{line}"
      end
  }
  return pods_ary
end

def pubspec_supports_macos(file)
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return false;
  end
  File.foreach(file_abs_path) { |line|
    return true if line =~ /^\s*macos:/
  }
  return false
end

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  ephemeral_dir = File.join('Flutter', 'ephemeral')
  symlink_dir = File.join(ephemeral_dir, '.symlinks')
  symlink_plugins_dir = File.join(symlink_dir, 'plugins')
  system("rm -rf #{symlink_dir}")
  system("mkdir -p #{symlink_plugins_dir}")

  # Flutter Pods
  generated_xcconfig = parse_KV_file(File.join(ephemeral_dir, 'Flutter-Generated.xcconfig'))
  if generated_xcconfig.empty?
    puts "Flutter-Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
  end
  generated_xcconfig.map { |p|
    if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
      symlink = File.join(symlink_dir, 'flutter')
      File.symlink(File.dirname(p[:path]), symlink)
      pod 'FlutterMacOS', :path => File.join(symlink, File.basename(p[:path]))
    end
  }

  # Plugin Pods
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.map { |p|
    symlink = File.join(symlink_plugins_dir, p[:name])
    File.symlink(p[:path], symlink)
    if pubspec_supports_macos(File.join(symlink, 'pubspec.yaml'))
      pod p[:name], :path => File.join(symlink, 'macos')
    end
  }

  if defined?($FirebaseSDKVersion)
    Pod::UI.puts "#{pubspec['name']}: Using user specified Firebase SDK version for FirebaseFirestore framework: '#{$FirebaseSDKVersion}'"
    firebase_sdk_version = $FirebaseSDKVersion
  else
    firebase_core_script = File.join(File.expand_path('..', File.expand_path('..', File.expand_path('..', File.expand_path('..', File.dirname(__FILE__))))), 'firebase_core/firebase_core/ios/firebase_sdk_version.rb')
    if File.exist?(firebase_core_script)
      require firebase_core_script
      firebase_sdk_version = firebase_sdk_version!
      Pod::UI.puts "#{pubspec['name']}: Using Firebase SDK version '#{firebase_sdk_version}' defined in 'firebase_core for FirebaseFirestore framework'"
    else
      raise "Error - unable to locate firebase_ios_sdk.rb script in firebase_core, and no FirebaseSDKVersion specified"
    end
  end

  pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => "#{firebase_sdk_version}"
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

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-x64, locale de-DE)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.5)
[✓] IntelliJ IDEA Ultimate Edition (version 2019.3.1)
[✓] VS Code (version 1.62.3)
[✓] Connected device (2 available)

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand
Dart SDK 2.14.4
Flutter SDK 2.5.3
test_project 1.0.0+1

dependencies:
- cupertino_icons 1.0.4
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]

dev dependencies:
- cloud_firestore 3.1.1 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- flutter_lints 1.0.4 [lints]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:
- async 2.8.1 [collection meta]
- boolean_selector 2.1.0 [source_span string_scanner]
- characters 1.1.0
- charcode 1.3.1
- clock 1.1.0
- cloud_firestore_platform_interface 5.4.6 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 2.6.1 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- collection 1.15.0
- fake_async 1.2.0 [clock collection]
- firebase_core 1.10.2 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_core_platform_interface 4.2.0 [collection flutter meta plugin_platform_interface]
- firebase_core_web 1.4.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- js 0.6.3
- lints 1.0.1
- matcher 0.12.10 [stack_trace]
- meta 1.7.0
- path 1.8.0
- plugin_platform_interface 2.0.2 [meta]
- sky_engine 0.0.99
- source_span 1.8.1 [collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- test_api 0.4.2 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0 [collection]
- vector_math 2.1.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions