2015-12-07 53 views
3

我試圖爲我的ios應用程序和ios手錶套件使用一個框架(Realm.framework)。 我嘗試了很多方法,但都沒有成功。任何人都可以給我一個如何編寫一個pod文件來共享iOS應用程序和手錶應用程序之間的框架的例子嗎?如何使用cocoapod爲ios應用程序和手錶擴展程序包含共享框架

隨着出莢文件中的任何表擴張對象,我得到了一個錯誤說:

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文件:

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 

我把它與「吊艙安裝」警告跑,但我的工作空間無法運行。

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文件有太多錯誤。

我也試着像豆莢文件: 「[!]目標不同的平臺」

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 

然後我得到了錯誤。

在我podspec,我已經添加行:

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

誰能告訴我應該如何辦呢?

回答

1

運行pod install後,您看到的警告不應該出現,並且明確是CocoaPods/Xcodeproj中的錯誤。這似乎是相關的UUID生成和警告你可能已經看到有關還有:

[!] [Xcodeproj] Generated duplicate UUIDs: 
… 

您的Podfile兩個目標的具體的依賴定義組。 無法將Podfile中的隱式根目標鏈接到您的應用及其擴展,因爲它們在不同的平臺上。這意味着你必須刪除第三/第四行:

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" 
相關問題