Reputation: 209
I tried to use one framework (Realm.framework) for both of my ios app and ios watch kit. I tried many ways, none of them work. Could anyone give me an example of how to write a pod file to share a framework between ios app and watch app?
With out any watch extension target in pod file, I got an error saying:
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'
Then I added target for watch extension to my pod file. Here is my pod file:
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
I got it run with warnings with "pod install", but my workspace failed to run.
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.
There are so many errors in my Pods-myApp Watch Extension-Realm file.
I also tried pod file like:
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
Then I got "[!] Targets with different platforms" error.
In my podspec, I already added lines:
s.platform = :ios
s.platform = :ios, "8.0"
s.platform = :watchos
s.platform = :watchos, "2.0"
Could anyone show me how it should be done?
Upvotes: 3
Views: 1927
Reputation: 7806
The warnings, you saw, after running pod install
shouldn't appear and are definitively a bug in CocoaPods / Xcodeproj. That seems to be related to the UUID generation and the warning you might have seen about that as well:
[!] [Xcodeproj] Generated duplicate UUIDs:
…
You have two target specific dependency definition groups in your Podfile. You can't link to the implicit root target in the Podfile to both your app and its extension as their are on different platforms. That means you have to remove the 3rd/4th line:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
#link_with 'myApp', 'myApp Watch Extension' # <= REMOVE this line.
…
I can't reproduce the error you're seeing in Xcode about the rejection of targets as implicit dependencies. As I don't have your podspec, I can't reproduce it exactly, but from what I see it shouldn't matter as long as your podspec doesn't declare any dependencies.
Beside that, it is sufficient to declare the platform availability by just those two lines in the podspec:
s.platform = :ios, "8.0"
s.platform = :watchos, "2.0"
Upvotes: 1