Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No such module error on using swift package in cocoapods generated targets #11214

Open
1 task done
soumyamahunt opened this issue Feb 20, 2022 · 3 comments
Open
1 task done

Comments

@soumyamahunt
Copy link

Report

What did you do?

I added swift packages to pods project in post_install hook but got the following error on project build:
Screenshot 2022-02-20 at 4 53 43 PM

What did you expect to happen?

I expected I will be able to build and run project after adding swift package to the pod targets.

What happened instead?

Got error No such module 'Algorithms' where Algorithms is a target in the swift-algorithms package.

CocoaPods Environment

[!] The signature of CLAide#arguments has changed. Use CLAide::Argument (Pod::Command::Lib::Archive: [["[NAME]", :optional]])
objc[55892]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libamsupport.dylib (0x1f0307678) and /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x107f8c2c8). One of the two will be used. Which one is undefined.
objc[55892]: Class AMSupportURLSession is implemented in both /usr/lib/libamsupport.dylib (0x1f03076c8) and /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x107f8c318). One of the two will be used. Which one is undefined.

Stack

   CocoaPods : 1.11.2
        Ruby : ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]
    RubyGems : 3.0.3.1
        Host : macOS 12.2.1 (21D62)
       Xcode : 13.2.1 (13C100)
         Git : git version 2.32.0 (Apple Git-132)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib
Repositories : cocoapods - git - https://github.com/CocoaPods/Specs.git @ 473d7cf434dea6626d2a9c5667d078b05fb65753

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

Installation Source

Executable Path: /usr/local/bin/pod

Plugins

cocoapods-archive                  : 0.0.2
cocoapods-deintegrate              : 1.0.5
cocoapods-packager                 : 1.5.0
cocoapods-plugins                  : 1.0.0
cocoapods-rome                     : 1.0.1
cocoapods-search                   : 1.0.1
cocoapods-stats                    : 1.1.0
cocoapods-trunk                    : 1.6.0
cocoapods-try                      : 1.2.0
cocoapods-user-defined-build-types : 0.0.7

Podfile

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'Example' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Example
  pod 'Alamofire'
end

post_install do |installer|
  swift_package = installer.pods_project.new Xcodeproj::Project::Object::XCRemoteSwiftPackageReference
  swift_package.repositoryURL = "https://github.com/apple/swift-algorithms.git"
  swift_package.requirement = {
    "kind" => "upToNextMajorVersion",
    "minimumVersion" => "1.0.0"
  }

  swift_package_product = installer.pods_project.new Xcodeproj::Project::Object::XCSwiftPackageProductDependency
  swift_package_product.package = swift_package
  swift_package_product.product_name = "Algorithms"

  swift_package_build_file = installer.pods_project.new Xcodeproj::Project::Object::PBXBuildFile
  swift_package_build_file.product_ref = swift_package_product
  swift_package_build_file.referrers << installer.pods_project['Frameworks']

  installer.pods_project.root_object.package_references << swift_package
  installer.pods_project.native_targets
   .select { 
     |target| installer.generated_pod_targets.any? { |pod| pod.pod_name == target.name }
   }.each do |target|
    target.frameworks_build_phase.files << swift_package_build_file
    target.package_product_dependencies << swift_package_product
  end
end

Project that demonstrates the issue

Sample project is hosted in this repo in Example directory.

@soumyamahunt
Copy link
Author

Build log: Build Example_2022-02-26T16-03-05.txt

@osrufung
Copy link

@mfazekas
Copy link

I don't think it's a cocoa pods issue, it's more a way of how Xcode works.

See https://github.com/mfazekas/pods-spm-dep-poc/blob/main/README.md#user-content-swift-import-paths

And the code to address this is here:
https://github.com/mfazekas/pods-spm-dep-poc/blob/b97b862ec667fed98085d133d8fdf7ff30ce60e7/spm_dependencies_poc.rb#L66-L73

   log " Adding workaround for Swift package not found issue"
   target = project.targets.find { |t| t.name == pod_name}
   target.build_configurations.each do |config|
      target.build_settings(config.name)['SWIFT_INCLUDE_PATHS'] ||= ['$(inherited)']
      search_path = '${SYMROOT}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/'
      unless target.build_settings(config.name)['SWIFT_INCLUDE_PATHS'].include?(search_path)
         target.build_settings(config.name)['SWIFT_INCLUDE_PATHS'].push(search_path)
      end
   end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants