4

I am unable to successfully run a WatchKit app using my installed CocoaPods and am getting a "dyld: Library not loaded...Reason: image not found" error.

The environment is as follows: Swift 2.0, WatchKit 2.0, CocoaPods 0.38.2, Xcode 7 Beta 4 with a Project using some internal CocoaPods I developed for an iPhone app with a WatchKit extension.

I have built a number of internally used CocoaPods that contain common code I would like to invoke from both my main app and the WatchKit extension. Below is the Podfile:

source 'https://github.com/CocoaPods/Specs.git'
source 'http://<local-git>/podspecs.git'

use_frameworks!

target 'Destinations511' do
  platform :ios, '9.0'

  pod 'GoogleMaps'
  pod 'APIKit', :path => '~/Documents/Libraries/APIKit'
  pod 'DestinationsKit', :path => '~/Documents/Libraries/DestinationsKit'
end

target 'Destinations511 WatchKit Extension' do
   platform :watchos, '2.0'

   pod 'APIKit', :path => '~/Documents/Libraries/APIKit'
   pod 'DestinationsKit', :path => '~/Documents/Libraries/DestinationsKit'
end

I can build my main app and it runs as expected. I can compile the watch kit app, but when it runs, I get the following:

 dyld: Library not loaded: @rpath/APIKit.framework/APIKit Referenced from (...) Reason: image not found.

I have tried solutions mentioned for other dylib problems including:

  • ensured my Target->Build Settings->Runpath Search Paths includes @executable_path/Frameworks
  • tried adding APIKit.framework to Target->General->Embedded Binaries (which for some reason won't even add the framework when I select it)
  • deintegrated by Podfile and rebuilt it.
  • Added APIKit.framework to the Target->General->Linked Frameworks and Libraries

When I look at my Pods directory in Xcode, I see two instances of each Framework (which I assume is because there is one for the app and one for the watch). All of them stay red even when I have successfully built and am running the iPhone app.

Likely related, but not sure how to solve, is that I get a number of warnings when I compile (regardless of target) along the lines of:

 ld: warning: linking against dylib not safe for use in application extensions: /Users/dan/Library/Developer/Xcode/DerivedData/MyProject-dlixiemzyqyquocjthlseirhdxcm/Build/Products/Debug-watchsimulator/Pods_MyProject_WatchKit_Extension.framework/Pods_MyProject_WatchKit_Extension

In the effort to be complete, here is the PodSpec for APIKit

Pod::Spec.new do |s|

  s.name         = "APIKit"
  s.version      = "1.1"
  s.summary      = "APIKit provides the basic classes and methods common to a number of our apps"

  s.homepage     = "http://.../apikit.git"
  s.license      = { :type => "MIT", :file => "LICENSE" }
  s.author             = { "me" => "me@me.com" }

  s.platform     = :ios
  s.ios.deployment_target = "9.0"
  s.watchos.deployment_target = "2.0"

   s.source       = { :git => "http://my-git-location/apikit.git", :tag => "#{s.version}" }

  s.source_files  = "APIKit"

  s.frameworks = "UIKIt", "CoreLocation"

  s.requires_arc = true

end
Dan Nichols
  • 769
  • 1
  • 7
  • 19

1 Answers1

0

This is a little counterintuitive, and results in a warning from CocoaPods when you install/update pods, but I fixed this problem by setting EMBEDDED_CONTENT_CONTAINS_SWIFT to NO in the WatchKit Extension’s build settings, even though it contained Swift. The app still runs, and it’s in the App Store, but CocoaPods still warns me about this setting.

Jeff Kelley
  • 19,021
  • 6
  • 70
  • 80