【问题标题】:How to use cocoapod to include shared framework for both ios app and watch extension如何使用 cocoapod 包含 ios 应用程序和手表扩展的共享框架
【发布时间】:2015-12-07 21:06:41
【问题描述】:

我尝试为我的 ios 应用程序和 ios watch kit 使用一个框架 (Realm.framework)。 我尝试了很多方法,它们都不起作用。谁能给我一个例子,说明如何编写一个 pod 文件来在 ios app 和 watch app 之间共享一个框架?

在 pod 文件中没有任何监视扩展目标时,我收到一条错误消息:

Target 'Realm' of project 'Pods' was rejected as an implicit dependency for 'Realm.framework' because it doesn't contain platform 'watchsimulator' in its SUPPORTED_PLATFORMS 'iphonesimulator, iphoneos'
Target 'RealmSwift' of project 'Pods' was rejected as an implicit dependency for 'RealmSwift.framework' because it doesn't contain platform 'watchsimulator' in its SUPPORTED_PLATFORMS 'iphonesimulator, iphoneos'
Target 'Pods' of project 'Pods' was rejected as an implicit dependency for 'Pods.framework' because it doesn't contain platform 'watchsimulator' in its SUPPORTED_PLATFORMS 'iphonesimulator, iphoneos'

然后我在我的 pod 文件中添加了 watch 扩展的目标。这是我的 pod 文件:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
link_with 'myApp', 'myApp Watch Extension'

def shared_pods
  pod 'RealmSwift'
end

target 'myApp' do
    podspec :path => 'myapp.podspec'
    pod 'SnapKit'
    pod 'ChameleonFramework/Swift'
    pod 'Google-Mobile-Ads-SDK'
    shared_pods
end

target 'myApp Watch Extension' do
    podspec :path => 'myapp.podspec'
    platform :watchos, '2.0'
    shared_pods
end

我运行它时出现“pod install”警告,但我的工作区无法运行。

2015-12-07 15:45:46.402 ruby[17042:4339468] warning:  The file reference for "Realm.framework" is a member of multiple groups ("Products" and "Products"); this indicates a malformed project.  Only the membership in one of the groups will be preserved (but membership in targets will be unaffected).  If you want a reference to the same file in more than one group, please add another reference to the same path.
2015-12-07 15:45:46.402 ruby[17042:4339468] warning:  The file reference for "RealmSwift.framework" is a member of multiple groups ("Products" and "Products"); this indicates a malformed project.  Only the membership in one of the groups will be preserved (but membership in targets will be unaffected).  If you want a reference to the same file in more than one group, please add another reference to the same path.

我的 Pods-myApp Watch Extension-Realm 文件中有很多错误。

我也尝试过像这样的 pod 文件:

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
link_with 'myApp', 'myApp Watch Extension'

def shared_pods
  pod 'RealmSwift'
end

target 'myApp' do
    podspec :path => 'myapp.podspec'
    platform :ios, '8.0'
    pod 'SnapKit'
    pod 'ChameleonFramework/Swift'
    pod 'Google-Mobile-Ads-SDK'
    shared_pods
end

target 'myApp Watch Extension' do
    podspec :path => 'myapp.podspec'
    platform :watchos, '2.0'
    shared_pods
end

然后我收到“[!] Targets with different platforms”错误。

在我的 podspec 中,我已经添加了行:

  s.platform     = :ios
  s.platform     = :ios, "8.0"
  s.platform     = :watchos
  s.platform     = :watchos, "2.0"

谁能告诉我应该怎么做?

【问题讨论】:

    标签: ios cocoapods watchkit realm watchos-2


    【解决方案1】:

    运行pod install 后,您看到的警告不应该出现,并且肯定是 CocoaPods / Xcodeproj 中的错误。这似乎与 UUID 生成以及您可能已经看到的警告有关:

    [!] [Xcodeproj] Generated duplicate UUIDs:
    …
    

    您的 Podfile 中有两个特定于目标的依赖项定义组。 您无法将 Podfile 中的隐式根目标链接到您的应用程序及其扩展程序,因为它们位于不同的平台上。这意味着您必须删除第 3/4 行:

    source 'https://github.com/CocoaPods/Specs.git'
    use_frameworks!
    #link_with 'myApp', 'myApp Watch Extension' # <= REMOVE this line.
    …
    

    我无法重现您在 Xcode 中看到的关于将目标拒绝为隐式依赖项的错误。由于我没有您的 podspec,因此我无法准确复制它,但据我所知,只要您的 podspec 未声明任何依赖项,它就无关紧要。

    除此之外,仅通过 podspec 中的这两行来声明平台可用性就足够了:

    s.platform     = :ios, "8.0"
    s.platform     = :watchos, "2.0"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-11
      • 2021-12-30
      • 2015-02-14
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多