Search code examples
iosswiftxcodecocoapodsios-extensions

Adding target to CocoaPods for extension


Okej, I'm fighting against this for several hours now, and I'm completetly out of ideas. I'm creating app that has Action Extension needed for getting currently watched website URL. I need to share some code between app and extension (mainly network API), so I need to share libs for it also (alamofire etc.).

Here is my CocoaPods

use_frameworks!

target 'xxxExtension' do
pod 'ObjectMapper', '~> 2.2'
pod 'SwiftyJSON'
pod 'Alamofire', '~> 4.0'
pod 'Nuke', '~> 4.0'
pod -
pod -
end

target 'yyyMain' do
pod 'ObjectMapper', '~> 2.2'
pod 'SwiftyJSON'
pod 'Alamofire', '~> 4.0'
pod 'Nuke', '~> 4.0'
pod -
pod -
pod -
pod -
pod -
pod -
    target 'yyyMainTests' do
    inherit! :search_paths
    pod -
    pod -
    pod -
    pod -
    pod -
    end
end

As you can see I use implicit abstract target for use_frameworks, I've tried to move pods that are share there, but that didn't changed much. Created abstract_target myself, same error.

error: /Users/abc/Library/Developer/Xcode/DerivedData/yyyMain-fuuyjxathhqlfdczxrtmfewlpcpe/Build/Products/Debug-iphoneos/xxxExtension.appex: No such file or directory

Any ideas what's going on?


Solution

  • Ok, that was a bit tricky and I've made few changes that may have resulted in solving the problem.

    First was adding

        post_install do |installer_representation|
        installer_representation.pods_project.targets.each do |target|
            if target.name.start_with? "Pods-extensionName"
                target.build_configurations.each do |config|
                    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'AF_APP_EXTENSIONS=1']
                end
            end
        end
    end
    

    To podfile.

    Second one was (aside of all cleaning, rebuilding and deleting derived data) to manually remove binaries associations. To do so one needs to enter project settings -> targets -> app -> general -> (on bottom) Embedded Binaries and delete *.appex file.

    Additional it may be required to go to build phases and remove link binary with Libaries.

    Last thing to do is reinstall pod by "pod install" and new links should be recreated on cleaned project.

    Goodluck!