I'm implementing an iOS framework written on Swift. This framework has an internal dependency on a C based static library. To make it work and based on some tutorials I've made a module map similar to this:
framework module Module {
umbrella header "Module.h"
explicit module ModuleDep {
private header "header1.h"
}
export *
}
Based on that I can include C code in Swift like this:
import Module.ModuleDep
When export framework manually everything seems to work just fine. It is a sure thing, I want to have Cocoapods support for my framework with code visibility (easier to debug). The podspec, that make it work was this (some parts are omitted):
Pod::Spec.new do |s|
s.platform = :ios
s.ios.deployment_target = '12.0'
s.module_map = "Module.modulemap"
s.source_files = "Module/*.{h,swift}", "ModuleDep/*.h"
s.vendored_libraries = "ModuleDep/*.a"
s.swift_version = "5.1"
end
From my understanding, vendored_libraries is used when this is the artifact you are providing to your users and that is why I don't like this solution.
I've also tried this spec variant:
Pod::Spec.new do |s|
s.platform = :ios
s.ios.deployment_target = '12.0'
s.module_map = "Module.modulemap"
s.source_files = "Module/*.{h,swift}", "ModuleDep/*.h", "ModuleDep/*.a"
s.swift_version = "5.1"
end
but it doesn't compile.
So what is the correct way to do this? Or what have I done wrong?
Since you are using a static library as a dependency then you must specify it as a library in your podspec file. Which is why your second approach is not working because it's a library not a source file.
As mentioned in the docs vendored_libraries are for libraries that come shipped with the Pod. Also in your case that C based static library is a dependency which must be shipped with the Pod. Thus using vendored_libraries should be ok in your case.
Related
We have created a CocoaPod which is an XCFramework that has dependencies on other CocoaPods. When we run the demo example app or install the pod in a new app, it works, however this is logged to the console on launch (repeated for many classes):
objc[38875]: Class OTSubscriber is implemented in both
/Users/MyUser/Library/Developer/CoreSimulator/Devices/8DD81910-DD40-4BD7-9355-8A0C78EFD32E/data/Containers/Bundle/Application/60E8C18A-37DC-4C2B-AEB3-E88C3A7C4D96/MyCocoaPod_Example.app/Frameworks/MyFramework.framework/MyFramework
(0x10e3fd660) and
/Users/MyUser/Library/Developer/CoreSimulator/Devices/8DD81910-DD40-4BD7-9355-8A0C78EFD32E/data/Containers/Bundle/Application/60E8C18A-37DC-4C2B-AEB3-E88C3A7C4D96/MyCocoaPod_Example.app/MyCocoaPod_Example
(0x10c8abd80). One of the two will be used. Which one is undefined.
This class is from OpenTok, which is a dependency specified for the pod used in the framework. The message seems to reveal CocoaPods is installing the dependencies on the app in addition to the framework, causing this issue. The app itself shouldn't have any dependencies except this framework.
Perhaps something was done incorrectly in the pod creation process? These are the steps we took:
Create an Xcode framework project, add a Podfile listing its dependencies, build out the framework's functionality
Create an XCFramework from the framework's xcworkspace
Create the pod using pod lib create MyCocoaPod choosing iOS, Swift, include demo, none and no for testing
Update the Podspec:
Pod::Spec.new do |s|
s.name = 'MyCocoaPod'
s.version = '1.0.0'
s.summary = 'Summary'
s.description = <<-DESC
'Description'
DESC
s.homepage = 'https://myhomepage.com'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Author' => 'auther#somedomain.com' }
s.ios.deployment_target = '12.0'
s.source = { :git => 'https://github.com/user/git-repo.git', :tag => s.version.to_s }
s.vendored_frameworks = 'MyFramework.xcframework'
s.swift_version = '5.5.2'
s.dependency 'OpenTok', '2.21.3'
# Needed to pass lint validation
s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
end
Drag and drop MyFramework.xcframework into Pods/Development Pods/MyCocoPod
Update the example's Podfile to specify BUILD_LIBRARY_FOR_DISTRIBUTION = YES:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
Run pod install in Example directory - note this will cause the framework to be moved to the root level in Finder and under a Frameworks group in Xcode
Update the example app's code to import and use MyFramework
Commit, tag, and push the changes to the repo
Push the Podspec to the specs repo
Not sure if this is your case but maybe you are falling in a scenario which happened to me,
meaning a dynamic framework that depends on a static framework. In such scenario, your dynamic framework would end up embedding the static one in his resulting binary. Then, in order to import your dynamic framework in the project, you will import with the setting “Embed and sign” for example, as that’s indeed a dynamic one, along with the other static framework which your dynamic one depends on. This causes the duplicated implementation ( your app including the static dependency + the dynamic one embedding inside the same dependency.
What you could do if this is your case, is to make sure that the dynamic framework configuration is changed to be static (static xcframework to be precise) , maybe outside cocoa pod as first step if that simplifies. Code wise would be the same, but it will “link” to the dependency (OpenTok for example) rather than embedding it. As result, once imported in the app, it should be imported only once, as your custom framework links to it and does not embeds it, finally avoiding the duplicated implementation. (static frameworks are imported with “Do not embed” which means that they will be merged in compile time to the app executable)
I'm building a framework using cocoapods. Now, I have it in a private repository with a private spec repo. I want to distribute this framework not as open source, but closed source. Basically, I want to distribute only the .framework file, already compiled. This way, I will avoid to expose my source code to externals.
I don't know how to tell cocoapods to distribute the compiled file.
After compiling your framework, you'll want to create a separate, public repository to use for distribution. That is where you will place your compiled framework, podspec, license, readme files, etc.
The podspec is a bit different for distributing frameworks rather than source code. See example:
Pod::Spec.new do |s|
s.name = 'YourFrameworkName'
s.version = '1.7.0'
s.summary = 'The YourFrameworkName iOS SDK enables you to embed state-of-the-art real-time goodness into your iOS app.'
s.homepage = 'http://example.com'
s.author = { 'Name' => 'info#example.com' }
s.license = { :type => 'Custom', :file => 'LICENSE' }
s.platform = :ios
s.source = { :http => 'https://github.com/example/YourFrameworkName/releases/download/1.7.0/YourFrameworkName.zip' }
s.ios.deployment_target = '9.0'
s.ios.vendored_frameworks = 'YourFrameworkName.framework'
s.dependency 'SwiftyJSON', '3.1.4'
end
Once all that is set up, you can publish the pod spec the normal way.
Keep in mind, and this is an important consideration, that your compiled framework written in Swift will only be usable in projects that use the exact same Swift version. You will quickly run into this limitation as people start using your framework in different projects with various Swift versions.
First, you create a sample project and install the pods(the library which you want to release as SDK.framework) for the project.
Then see the below-attached image to get the .framework extension file to distribute to the public.
You can do this by pointing s.source of the podspec file to a zip file of your framework and its source. No need to expose your source in a public repository.
ex.
spec.source = { :http => 'https://bitbucket.org/publicRepo/yourframework.zip' }
Hoping somebody has already solved this; I'm trying to wrap a third-party library (Airwatch) in a cocoapod for better management across our apps. I'm having a hell of a time trying to get this to work, though. I've created a pod around a static library, but this one is a dynamic framework, and I'm having a hell of a time getting it to compile. The headers from the framework just aren't accessible in the containing app....
Here's what I have tried already:
When I set vendored_libraries in podspec i can't seem to access headers with either quotes or <>. Xcode just complains as 'Not Found'
Next, I tried adding the path of the headers in the framework as source_files like so
s.source_files = 'Pod/Classes/**/*','Pod/Framework/AWSDK.framework/Versions/A/Headers/*.h'
This allows xcode to find the header for an import like:
import "AWSDKCore.h" //Documented as the framework's main header
But this throws an error for the existing imports within the original framework:
I figured this was a bad idea, but I thought I'd try naming my cocoapod the same name as the Framework (which should keep the import path). So, this throws a bunch of errors saying some enums either aren't declared or are declared twice.
If anybody has thoughts, I'd be eternally greatful...
Just for reference here's my podspec:
Pod::Spec.new do |s|
s.name = "AirwatchSDK"
s.version = "0.1.0"
s.summary = "A short description of AirwatchSDK."
s.homepage = "https://github.com/<GITHUB_USERNAME>/AirwatchSDK"
s.license = 'MIT'
s.author = { "xxxxx" => "xxxx" }
s.source = { :git => "https://github.com/<GITHUB_USERNAME>/AirwatchSDK.git", :tag => s.version.to_s }
s.platform = :ios, '8.0'
s.requires_arc = true
#s.module_name = 'AWSDK'
s.source_files = 'Pod/Classes/**/*','Pod/Framework/AWSDK.framework/Versions/A/Headers/*.h'
s.vendored_frameworks = 'Pod/Framework/AWSDK.framework'
s.frameworks = 'CFNetwork','CoreData','CoreFoundation','CoreGraphics','CoreLocation','CoreTelephony','CoreText'
s.libraries = 'stdc++','z','sqlite3','c++'
end
Since I figured out my own answer, I thought I'd post it here for the next guy...
The key, it turns out, was to not have 'source_files' (or to comment it out). I'm not sure if that is a bug or not, but my final podspec had vendored_framework set and source_files not set like so:
#can't have source files if you want to access vendor framework
#s.source_files = 'Pod/Classes/**/*'
# airwatch framework.
s.vendored_frameworks = 'AWSDK.framework'
I am trying to modulize my app by splitting it in different sub projects.
Inspired by this idea. So I splited my project to static libraries followed by that tutorial. I created a first library with some costume UIHelpers/Views. It has some dependencies which I defined in PodSpec file followed by AFNetworking example. (one of the dependencies is Choosy). I stored this library in bitBucket. Everything is working fine for that library(I can build it in Xcode). The problem start when I create a Model Library. I specify Git path of UIHelpers in the Model PodFile. Every time I get an error of No visible #interface for a category in Choosy (the error come from CocoaPod NOT in my project, the category is imported in the .mfile). I tried to play with link flags -ObjC,$(inhereted),-force_load included all of them.Objective-C categories in static library I cleaned the derived data.
I read the CocoaPodTroubleShoutes.
Can somebody suggest what can be tried. There is a lot of question in stuck regarding that compile error but none of them helped me.
I believe the problem somewhere in my PodSpec(cant be sure) pod lib linit I receive :- ERROR | [iOS] Choosy/Choosy/Model/ChoosyAppInfo.m:32:19: error: no visible #interface for 'UIImage' declares the selector 'applyMaskImage:completion:'
My PodSec:
Pod::Spec.new do |s|
#I tried this options:
#s.xcconfig = { 'OTHER_LDFLAGS' => $(inherited) }
#s.compiler_flags = '-ObjC'
#'-all_load'
#$(inherited)
#'-DOS_OBJECT_USE_OBJC=0', '-Wno-format'
#'-force_load'
s.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>','#import <CoreGraphics/CoreGraphics.h>','#import "ARNStyles.h"'
s.description = <<-DESC
A longer description of ARNUIHelpers in Markdown format.
DESC
s.homepage = "http://EXAMPLE/ARNUIHelpers"
s.platform = :ios, "7.0"
s.ios.deployment_target = "7.0"
s.source_files = 'UIHelpers/**/*.{h,m}'
s.requires_arc = true
s.subspec 'Choosy' do |ss|
ss.requires_arc = true
ss.compiler_flags = '-force_load'
ss.platform = :ios, "7.0"
ss.dependency 'Choosy'
# ss.xcconfig = { "FRAMEWORK_SEARCH_PATHS" => "$(PODS_ROOT)/Headers/Public/Choosy"}
# ss.ios.public_header_files = 'UIImage+ImageEffects.h'
end
s.subspec 'Dependencies' do |ss|
#ss.ios.public_header_files = 'UIImage+ImageEffects.h'
ss.requires_arc = true
ss.dependency 'FormatterKit'
end
end
In the end it was my fault. The previous developer copied those files from Choosy pod and included it manually.We still use Choosy in other places. Unfortunately the error wasn't clear enough to deduce what was wrong.
My podspec requires a static library (OpenSSL). For convenience, I'm shipping the library with the pod.
The static library contains:
Binaries: MyPod/openssl/bin/libcrypto.a and MyPod/openssl/bin/libsll.a
Headers: MyPod/openssl/include/openssl/*.h
Its own license (in addition to my project's license): MyPod/openssl/include/LICENSE
What is the proper way of expressing this in my podspec? I've seen various example that use combinations of the following properties and I'm currently trying different combinations:
source_files
public_header_files
private_header_files
preserve_paths
libraries
xcconfig
vendored_libraries
Or even better, can I define this static library in a subspec?
I managed to add the static library as a subspec. I prefer this approach because it uses the build shipped with my pod by default, and also enables users to provide their own build if they so desire.
As mentioned, the static library is OpenSSL but the following applies to any static library. I'm using the following directory structure:
libraries/openssl-1.0.1e/include/openssl/*.h
libraries/openssl-1.0.1e/LICENSE
libraries/openssl-1.0.1e/lib/*.a
The resulting subspec would be:
s.subspec 'OpenSSL' do |openssl|
openssl.preserve_paths = 'libraries/openssl-1.0.1e/include/openssl/*.h', 'libraries/openssl-1.0.1e/include/LICENSE'
openssl.vendored_libraries = 'libraries/openssl-1.0.1e/lib/libcrypto.a', 'libraries/openssl-1.0.1e/lib/libssl.a'
openssl.libraries = 'ssl', 'crypto'
openssl.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/libraries/openssl-1.0.1e/include/**" }
end
Line by line:
openssl.preserve_paths = 'libraries/openssl-1.0.1e/include/openssl/*.h', 'libraries/openssl-1.0.1e/include/LICENSE'
Preserve headers and the license file. We will use the headers below.
openssl.vendored_libraries = 'libraries/openssl-1.0.1e/lib/libcrypto.a', 'libraries/openssl-1.0.1e/lib/libssl.a'
Tell CocoaPods that we are shipping the above static libraries in the pod. This will preserve the files, as well as modifying LIBRARY_SEARCH_PATHS accordingly.
openssl.libraries = 'ssl', 'crypto'
Includes the libraries in "Other Linker Flags".
openssl.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/libraries/openssl-1.0.1e/include/**" }
Tells the project where to find the headers. We cannot use public_header_files because this is a subspec.
You can try do it like it's done here https://github.com/krzak/OpenSSL, or just use this Pod with you project if you find it convienence
pod 'OpenSSL', :podspec => 'https://raw.github.com/krzak/OpenSSL/master/OpenSSL.podspec'