trinhngocthuyen / cocoapods-spm

A CocoaPods plugin to add SPM dependencies to CocoaPods-based projects
MIT License
53 stars 10 forks source link

[Bug] NoMethodError - undefined method `use_default_xcode_linking?' for nil:NilClass #106

Closed AlexMoumou closed 1 month ago

AlexMoumou commented 4 months ago

What happened?

This is my Gemfile:

source 'https://rubygems.org'

source 'https://rubygems.org'

gem 'cocoapods'
gem 'cocoapods-xcconfig-hooks'
gem 'cocoapods-spm'

And the podfile as specified in the usage:

platform :ios, '15.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 flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', '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 Generated.xcconfig, then run flutter pub get"
end

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

flutter_ios_podfile_setup

plugin "cocoapods-spm"
plugin "cocoapods-xcconfig-hooks"

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  spm_pkg "MeetingDoctorsSDK",
  :url => "https://github.com/Meeting-Doctors/meetingdoctors-sdk-spm",
  :branch => "main", 
  :linking => {
  :use_default_xcode_linking => true,
  }

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
  target 'RunnerTests' do
    inherit! :search_paths
  end
end

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

After executing bundle exec pod install:

Error

NoMethodError - undefined method `use_default_xcode_linking?' for nil:NilClass
/Library/Ruby/Gems/2.6.0/gems/cocoapods-spm-0.1.4/lib/cocoapods-spm/resolver/recursive_target_resolver.rb:29:in `block in resolve_recursive_targets'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-spm-0.1.4/lib/cocoapods-spm/resolver/recursive_target_resolver.rb:28:in `each'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-spm-0.1.4/lib/cocoapods-spm/resolver/recursive_target_resolver.rb:28:in `resolve_recursive_targets'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-spm-0.1.4/lib/cocoapods-spm/resolver/recursive_target_resolver.rb:15:in `resolve'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-spm-0.1.4/lib/cocoapods-spm/resolver.rb:24:in `each'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-spm-0.1.4/lib/cocoapods-spm/resolver.rb:24:in `resolve'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-spm-0.1.4/lib/cocoapods-spm/patch/installer.rb:59:in `block in resolve_spm_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.15.2/lib/cocoapods/user_interface.rb:64:in `section'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-spm-0.1.4/lib/cocoapods-spm/patch/installer.rb:57:in `resolve_spm_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-spm-0.1.4/lib/cocoapods-spm/patch/installer.rb:13:in `block in <class:Installer>'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:162:in `install!'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.15.2/lib/cocoapods/command/install.rb:52:in `run'
/Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.15.2/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.15.2/bin/pod:55:in `<top (required)>'
/Library/Ruby/Gems/2.6.0/bin/pod:23:in `load'
/Library/Ruby/Gems/2.6.0/bin/pod:23:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `load'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `kernel_load'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/cli/exec.rb:28:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/cli.rb:463:in `exec'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/cli.rb:27:in `dispatch'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/cli.rb:18:in `start'
/Library/Ruby/Gems/2.6.0/gems/bundler-1.17.2/exe/bundle:30:in `block in <top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/Library/Ruby/Gems/2.6.0/gems/bundler-1.17.2/exe/bundle:22:in `<top (required)>'
/usr/bin/bundle:23:in `load'
/usr/bin/bundle:23:in `<main>'

CocoaPods environment

Stack

   CocoaPods : 1.15.2
        Ruby : ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]
    RubyGems : 3.0.3.1
        Host : macOS 14.1.2 (23B92)
       Xcode : 15.1 (15C65)
         Git : git version 2.39.3 (Apple Git-145)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib
Repositories : bitbucket-meetingdoctors-team-cocoapods-specs - git - https://bitbucket.org/meetingdoctors-team/cocoapods-specs.git @ 6264c32f2b5dc71f88ec1a6a132a29951dc42229

               trunk - CDN - https://cdn.cocoapods.org/

Installation Source

Executable Path: /Library/Ruby/Gems/2.6.0/bin/pod

Plugins

cocoapods-deintegrate : 1.0.5
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.1
cocoapods-spm         : 0.1.4
cocoapods-trunk       : 1.6.0
cocoapods-try         : 1.2.0

Podfile

# Uncomment this line to define a global platform for your project
platform :ios, '15.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 flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', '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 Generated.xcconfig, then run flutter pub get"
end

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

flutter_ios_podfile_setup

plugin "cocoapods-spm"

target 'Runner' do
  # use_frameworks!
  use_modular_headers!

  spm_pkg "MeetingDoctorsSDK",
  :url => "https://github.com/Meeting-Doctors/meetingdoctors-sdk-spm",
  :branch => "main", 
  :linking => {
  :use_default_xcode_linking => true,
  :linker_flags => ["-ld_classic"]
  }

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
  target 'RunnerTests' do
    inherit! :search_paths
  end
end

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

Anything else?

No response

trinhngocthuyen commented 2 months ago

Hi there. Sorry for the late response. I've checked this case, there are few things to do in order to integrate this MeetingDoctorsSDK package:

  1. Let's omit the :linking option. The : use_default_xcode_linking doesnt work in some corner cases.
  2. Let's add the :products option to specify what products to use. By default, it's implicitly inferred as the name of the package (MeetingDoctorsSDK). But in this case, the library products declared in the manifest is MeetingDoctorsSDKWrapper, not MeetingsDoctorSDK (see: here)

To sum up, the spm_pkg declaration would be:

  spm_pkg "MeetingDoctorsSDK",
          :url => "https://github.com/Meeting-Doctors/meetingdoctors-sdk-spm",
          :branch => "main",
          :products => ["MeetingDoctorsSDKWrapper"]

I've tried that on the example project and it works on my end. Thank you!