Can App Clip be used in an iOS Cocoapods project?

2.4k Views Asked by At

Our App was created in 2018 mid using Swift 4, and other 3rd party depended with Cocoapods. I add one Clip target, the project structure is different from that given by the download link under session. Run this target, here are the crash errors:

Reason: image not found

dyld: Library not loaded: @rpath/Alamofire.framework/Alamofire
  Referenced from: /private/var/containers/Bundle/Application/57185773-B735-4EE5-BB51-790DF004A85B/kt_iOS_Clip.app/kt_iOS_Clip
  Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib:/Developer/Library/PrivateFrameworks/GPUTools.framework/libglInterpose.dylib:/usr/lib/libMTLCapture.dylib

Here is Podfile:

platform :ios, '10.0'
inhibit_all_warnings!

target '<Main App>' do
    use_frameworks!
  
    pod 'SnapKit' , '4.2.0'                     
    pod 'Alamofire' , '4.7.3' 
    ......                  
    
  target '<Main App>Tests' do
    inherit! :search_paths
  end
  
  swift_41_pod_targets = ['Spring','PKHUD', 'FSPagerView', 'SQLite.swift','FaveButton']
  
  post_install do | installer |
      
      installer.pods_project.targets.each do |target|
          if target.name == 'Cache'
              target.build_configurations.each do |config|
                  level = '-Osize'
                  config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = level
                  puts "Set #{target.name} #{config.name} to Optimization Level #{level}"
              end
          end
          if swift_41_pod_targets.include?(target.name)
              
              target.build_configurations.each do |config|
                  
                  config.build_settings['SWIFT_VERSION'] = '4.1'
                  
              end
              
          end
          
      end
      
  end

  target '<Main App>UITests' do
    inherit! :search_paths
  end

end
5

There are 5 best solutions below

0
On

What worked for me is doing:

sudo gem install cocoapods --pre

Cocoapods latest stable release at the time of this post was not supporting the app clip target with cocoaPods.

0
On

YES, but NO at present (2020.7.15).

igor-makarov had commit an app clip support to master, now just wait for next CocoaPods release.

https://github.com/CocoaPods/CocoaPods/commit/3a5deed0adfa306307027753898cca5e23be14bd

0
On

I think the right way to do it is having another target (in my case I placed it outside the main one, because I only want a few pods).

However, Cocoapods needs to update something to export/setup everything right. Since App Clips were introduced recently, Cocoapods hasn't released a new stable version with the fix (https://github.com/CocoaPods/CocoaPods/pull/9882). So we just have to wait a bit, I guess. In the meantime, you can add the Embed Pods Frameworks manually and it will work fine.

Ref: https://developer.apple.com/forums/thread/652683?login=true

0
On

As other answers mentioned, separate app clip target and use_modular_headers! worked for me

platform :ios, '13.0'

target 'MainAppTarget' do
  
  use_frameworks!

  pod 'Firebase/Analytics'
  pod 'Firebase/RemoteConfig'

  target 'MainAppTargetTests' do
    inherit! :search_paths
  end

end

target 'AppClipTarget' do
  
  use_modular_headers!

  pod 'Firebase/Analytics'

  target 'AppClipTargetTests' do
    inherit! :search_paths
  end

  target 'AppClipTargetUITests' do
  end

end

2
On

I fixed this problem by adding another target in my podfile which pointed to the AppClip target

Ref: https://www.natashatherobot.com/cocoapods-installing-same-pod-multiple-targets/