我无法使用我安装的 CocoaPods成功运行WatchKit应用程序,并且正在获取“dyld:未加载库…原因:未找到图像”错误. 环境如下:Swift 2.0,WatchKit 2.0,CocoaPods 0.38.2,Xcode 7 Beta 4,项目使用我开发的
环境如下:Swift 2.0,WatchKit 2.0,CocoaPods 0.38.2,Xcode 7 Beta 4,项目使用我开发的一些内部CocoaPods,用于带有WatchKit扩展的iPhone应用程序.
我已经构建了许多内部使用的CocoaPods,它们包含我想从我的主应用程序和WatchKit扩展中调用的公共代码.下面是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
我可以构建我的主应用程序,它按预期运行.我可以编译监视工具包应用程序,但是当它运行时,我得到以下内容:
dyld: Library not loaded: @rpath/APIKit.framework/APIKit Referenced from (...) Reason: image not found.
我尝试过针对其他dylib问题提到的解决方案,包括:
>确保我的Target-> Build Settings-> Runpath搜索路径包括@ executable_path / Frameworks
>尝试将APIKit.framework添加到Target-> General->嵌入式二进制文件(由于某种原因,我选择它时甚至不会添加框架)
>由Podfile解体并重建它.
>将APIKit.framework添加到Target-> General-> Linked Frameworks and Libraries
当我在Xcode中查看我的Pods目录时,我看到每个Framework的两个实例(我假设是因为有一个用于应用程序,一个用于监视).即使我成功构建并运行iPhone应用程序,它们都会保持红色.
可能相关,但不确定如何解决,是当我编译(无论目标)时,我得到了一些警告:
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
为了完成,这里是APIKit的PodSpec
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这有点违反直觉,当您安装/更新pod时会导致CocoaPods发出警告,但我通过在WatchKit Extension的构建设置中将EMBEDDED_CONTENT_CONTAINS_SWIFT设置为NO来解决此问题,即使它包含Swift.该应用程序仍然运行,它在App Store中,但CocoaPods仍然警告我这个设置.