Please Help - Embedding custom framework that uses Cocoapods in sample App - xCode 9 - SWIFT

What is the right way to embed in simple MyApp a custom framework that uses Cocoapods for dependencies?
I read a lot o of tutorials and posts but no one solves the issue!
Please help I cant figure out.


SCENARIO:

I created a little test framework and i embedded it in a little consumer app following this simple tutorial [https://www.raywenderlich.com/5109-creating-a-framework-for-ios][1] just one like many others.

I get my simple example working.

Now i created a biggest framework MyFramework that uses itself some pods like firebase, alamofire and so on. MyFramworks builds correctly

Now i embed it in my consumer application MyApp and added MyFramework in “Embedded Binaries” and in “Linked Framework and Libraries” but I’M getting an error on MyFramwork when xCode is building MyApp:

Apple Mach-O Linker (ld) Error Group
lang: error: linker command failed with exit code 1 (use -v to see invocation)

giving me a lot of “Directory not found” errors in DerivedData for all installed Pods

I read a lot of posts but no one solved the issue



UPDATED SCENARIO:
I tried to replicate the problem in my little working test framework named testfwk.
The testapp is in a separated project, and in a separated folder like ls -la command:

MacBook-Pro:test david$ ls -l
total 0
drwxr-xr-x  12 david  staff  384 15 Ott 10:40 testapp
drwxr-xr-x  10 david  staff  320 15 Ott 10:14 testfwk

ls -l for testfwk folder:

MacBook-Pro:testfwk david$ ls -l
total 16
-rw-r--r--  1 david  staff  415 15 Ott 10:14 Podfile
-rw-r--r--  1 david  staff  290 15 Ott 10:14 Podfile.lock
drwxr-xr-x  8 david  staff  256 15 Ott 10:14 Pods
drwxr-xr-x  5 david  staff  160 15 Ott 10:49 testfwk
drwxr-xr-x@ 5 david  staff  160 15 Ott 10:14 testfwk.xcodeproj
drwxr-xr-x@ 5 david  staff  160 15 Ott 10:16 testfwk.xcworkspace
drwxr-xr-x  4 david  staff  128 14 Ott 15:58 testfwkTests

ls -l for testapp folder:

MacBook-Pro:testapp david$ ls -l
total 16
-rw-r--r--  1 david  staff  637 15 Ott 10:53 Podfile
-rw-r--r--  1 david  staff  290 15 Ott 10:40 Podfile.lock
drwxr-xr-x  8 david  staff  256 15 Ott 10:53 Pods
drwxr-xr-x  7 david  staff  224 15 Ott 10:20 testapp
drwxr-xr-x@ 5 david  staff  160 15 Ott 10:40 testapp.xcodeproj
drwxr-xr-x@ 5 david  staff  160 15 Ott 10:41 testapp.xcworkspace
drwxr-xr-x  4 david  staff  128 14 Ott 16:01 testappTests
drwxr-xr-x  4 david  staff  128 14 Ott 16:01 testappUITests

I add KingFisher via Coccoapods to testfwk, opened testfwk.xcworkspace and it builds succesfully, kingfisher import works on a sample swift class.

testfwk Podfile

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'

target 'testfwk' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for testfwk
  pod 'Kingfisher','~> 4.0'
  
  target 'testfwkTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

First time i opened testapp.xcodeproj, do a clean ad try to build but i get this error:

The testfwk was already added as embedded binary and library in my testapp like shown:

The framwork function testprint.hello() called from Viewcontroller of testapp was working right before adding pod to testfwk

Then i close xCode, cleaned derived data folder, opened testfwk and build it succesfully, opened testapp cleaned and try to build but i get the same error.

What is going wrong??? How can i get it working!!!
I need to embed my framework to set up my consumer app and do some adjusments, after that my idea is to use cocoapods to add my framework in following apps.
Anyoine can help? Thanks

After this i tried to add the KingFisher pod via Cocoapods to testapp application also using a similar podfile used for testfwk but changing target to ‘testapp’, the pod was installed succesfully but when i try to build testapp.xcworkspace i get the same error. I think this installation was unnecessary.
I think the testfwk is not able to build inside testapp and for some reason doesn’t see KingFisher pod

podfile for testapp

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

source 'https://github.com/CocoaPods/Specs.git'

target 'testapp' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for testapp
    pod 'Kingfisher','~> 4.0'

  target 'testappTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'testappUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

After I also tried to follow the accepted answer [https://stackoverflow.com/a/37415074/9880094][4]
i created a similar Podfile for testapp but i get a “Target not found error for ‘testfwk’ target” i think for path or folder issues"

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

source 'https://github.com/CocoaPods/Specs.git'

def facile_core_pods
  pod 'Kingfisher','~> 4.0'
end

target 'testapp' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for testapp
    facile_core_pods 

  target 'testappTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'testappUITests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'testfwk' do
    use_frameworks!
    facile_core_pods 
  end

end

Hi @darkvide, thanks for posting your question here. I understand you tried deleting your derived data, and still getting the Apple Mach-O Linker (ld) Error Group
lang: error: linker command failed with exit code 1 (use -v to see invocation)
error correct? When you deleted your derived data, did you try File > Workspace Settings > Grey Arrow to derived data file > Derived Data Folder > Deleted Project Folder w/ Derived Data?

If so, another option I could think of that has helped me with the same error was deleting and re-installing the pods from the podfile, quitting Xcode, and restarting my computer. I can relate to your frustration but hopefully if my suggestions don’t work then someone here can help out as well.

Best,
Gina

Hi, thanks for reply.
I will try your suggestion…
Can you provide a feedback for the UPDATED SCENARIO also.
Thanks in advance

Hi @darkvide,
One issue you might want to look out for is that when you specify a specific version of cocoapods, that might be incompatible with what your code.

So if for whatever reason your code does not compile, then it won’t compile/link. You might have to read the error messages in detail to see what the issue is.

cheers,

Jayant

Hi jayantvarma

I get it working ONLY with this steps:

  • Creating a framework testfwk, installing cocoapod Kingfisher in it, opening testfwk.xcworkspace bulding testfwk
  • Adding testapp.xcodeproj to testfwk.xcworkspace, linking testfwk.framework to testapp and adding testfwk.framework to embedded binaries, buld testapp, it works

This is ok but i wanted to link testfwk.xcodeproj directly in testapp.xcodeproj to both keep developing the framework and test directly in testapp.
In this specifically case i get the followinf error that non appearsbefore i install the Pod in testfwk framewokr:

Apple Mach-O Linker (ld) Error Groupt the following error:

Ld /Users/davide/Library/Developer/Xcode/DerivedData/testapp2-czyttnrayvnpuvcbpqzdmyhjgujq/Build/Products/Debug-iphoneos/testfwk.framework/testfwk normal arm64
cd /Users/davide/Documents/iOs/test/testfwk
export IPHONEOS_DEPLOYMENT_TARGET=11.4
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch arm64 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk -L/Users/davide/Library/Developer/Xcode/DerivedData/testapp2-czyttnrayvnpuvcbpqzdmyhjgujq/Build/Products/Debug-iphoneos -F/Users/davide/Library/Developer/Xcode/DerivedData/testapp2-czyttnrayvnpuvcbpqzdmyhjgujq/Build/Products/Debug-iphoneos -F/Users/davide/Library/Developer/Xcode/DerivedData/testapp2-czyttnrayvnpuvcbpqzdmyhjgujq/Build/Products/Debug-iphoneos/Kingfisher -filelist /Users/davide/Library/Developer/Xcode/DerivedData/testapp2-czyttnrayvnpuvcbpqzdmyhjgujq/Build/Intermediates.noindex/testfwk.build/Debug-iphoneos/testfwk.build/Objects-normal/arm64/testfwk.LinkFileList -install_name @rpath/testfwk.framework/testfwk -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -Xlinker -rpath -Xlinker @executable_path/…/…/Frameworks -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -miphoneos-version-min=11.4 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/davide/Library/Developer/Xcode/DerivedData/testapp2-czyttnrayvnpuvcbpqzdmyhjgujq/Build/Intermediates.noindex/testfwk.build/Debug-iphoneos/testfwk.build/Objects-normal/arm64/testfwk_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fembed-bitcode-marker -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -Xlinker -add_ast_path -Xlinker /Users/davide/Library/Developer/Xcode/DerivedData/testapp2-czyttnrayvnpuvcbpqzdmyhjgujq/Build/Intermediates.noindex/testfwk.build/Debug-iphoneos/testfwk.build/Objects-normal/arm64/testfwk.swiftmodule -framework Kingfisher -framework Pods_testfwk -compatibility_version 1 -current_version 1 -Xlinker -dependency_info -Xlinker /Users/davide/Library/Developer/Xcode/DerivedData/testapp2-czyttnrayvnpuvcbpqzdmyhjgujq/Build/Intermediates.noindex/testfwk.build/Debug-iphoneos/testfwk.build/Objects-normal/arm64/testfwk_dependency_info.dat -o /Users/davide/Library/Developer/Xcode/DerivedData/testapp2-czyttnrayvnpuvcbpqzdmyhjgujq/Build/Products/Debug-iphoneos/testfwk.framework/testfwk

ld: warning: directory not found for option ‘-F/Users/davide/Library/Developer/Xcode/DerivedData/testapp2-czyttnrayvnpuvcbpqzdmyhjgujq/Build/Products/Debug-iphoneos/Kingfisher’
ld: framework not found Kingfisher
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I think, in this case there is a problem linking pods because linking testfwk.xcodeproj (drag and drop to project navigator of testapp) it loose Pods referencesof the frameworks that ar not linked with testfwk.xcodeproj but contained instead in testfwk.xcworkspace in Pods module.
Do you have any idea how to achieve this?
Thank you

Hi I am trying to use cocoa pods in the framework but after build i am getting error no module found for all the module which i added in my pods.

This topic was automatically closed after 166 days. New replies are no longer allowed.