Cocoapods importing a framework to source code - ios

In my cocoapod for iOS, I have a essentially items:
Open-source classes (.m & .h files)
MyFramework.framework (.framework directory, header files, and .bundle for resources)
One of the open-source classes calls import <MyFramework.MyFramework.h> so it can use the components of MyFramework in its implementation. But because of this, I'm having trouble getting the podspec to pass the spec lint test (pod spec lint MyCocoapod.podspec). When I run the spec lint validation, it says:
ERROR | [iOS] [xcodebuild] .../MyFile.h:54:9: fatal error: 'MyFramework/MyFramework.h' file not found
While investigating, I noticed that the podspec does pass the spec lint validation if I remove that open-source class in the podspec's source_files section, s.source_files = 'MyFiles.{h,m}'. Any idea why my class can't import my custom framework during the spec lint validation?
The relevant code in the podspec looks like this:
s.preserve_paths = 'myframework/MyFramework.framework'
s.frameworks = 'Foundation', 'MyFramework'
s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '$(SRCROOT)/myframework/' }
s.public_header_files = 'MyFramework.framework/Headers/*.h', 'SourceCode/*.h'
s.source_files = 'SourceCode/*.{h,m}' # Crashes here - Source_file imports MyFramework.h. If I take this out, it passes spec lint validation

EDIT This process is now entirely handled by the vendored_frameworks option. This handles preserving the paths, the framework search paths, and linking to the project.

To include a framework you can use:
s.vendored_frameworks = 'path/to/SomeFramework.framework'
To include bundle files do:
s.resources ='path/to/SomeBundle.bundle'

Related

cocoa podspec subspec swift compatibility header file not found

Pod lib could not find mymodule-swift.h header.
One of my objc.m file imports following code.
#import <devillogin/devillogin-Swift.h>
Xcode build is success. Everything is ok.
But when I'm trying to distribute with pod, following error printed.
pod lib lint mymodule.podspec
fatal error: 'devillogin/devillogin-Swift.h' file not found
My mylib.podpec is as following
Pod::Spec.new do |s|
...
s.subspec 'DevilLogin' do |devilLogin|
devilLogin.source_files = 'devillogin/devillogin/source/**/*.*'
devilLogin.public_header_files = 'Pod/Headers/*.h'
devilLogin.dependency 'devil/DevilCore'
devilLogin.dependency 'KakaoSDK'
end
end
Is there any syntax in podspec for mylib-swift.h ?
I'm answering to myself.
I found that the issue only occur when it is in the subspec.
No problem with root podspec.
Consequently I couldn't find way to let my pod-subspec import "XXX-swift" header.
But I found workaround.
I referenced firebase frameworks which use many pod-subspecs.
https://github.com/firebase/firebase-ios-sdk
Just watched root pod spect and 1 subspec.
It distributes sub-specs as root pod spec which is success with 'XXX-swift.h' header
And each subspecs depend on it above.
There is Firebase.podspec and FirebaseDynamicLinks.podspec.
FirebaseDynamicLinks is standalone independent frameworks.
But it is actually subspec.
Firebase podspec defines subspec like followings.
This is workaround
s.subspec 'DynamicLinks' do |ss|
ss.dependency 'Firebase/CoreOnly'
ss.ios.dependency 'FirebaseDynamicLinks', '~> 7.9.0'
end
It defines DynamicLinks as subspec and define dependency on independent FirebaseDynamicLinks.
Done

Cocoapod podspec validation - Unknown DSL error occured

Im trying to upload the new version of my pod to cocoapods spec repo. The current live version is 0.3.1 and it is a framework build with swift 4.2. Now i updated the library and build with Xcode 11.1 (swift 5). But while linting the podspec file, im getting an unknown DSL error in the terminal.
I have tried with changing the name of podspec and with same framework. but no use. anyone please help
pod spec lint AsistaCore.podspec --verbose
Podspec file
Pod::Spec.new do |spec|
spec.name = 'AsistaCore'
spec.version = '1.0.0'
spec.summary = 'Official Asista SDK in Swift to access Asista Platform core feature'
spec.description = <<-DESC
The Asista SDK in Swift Core framework provides:
* Create new tickets
* Update Ticket State
* Add comments to ticket
* Asset list
* Update profile
* Knowledge Base Articles
DESC
spec.homepage = 'https://asista.com/developer'
spec.license = { :type => 'MIT', :file => 'LICENSE' }
spec.authors = { 'Cherrylabs' => 'vaisakh.kp#cherrylabs.com' }
spec.documentation_url = 'https://asista.com/developer/docs/asista-sdk-for-ios'
spec.platform = :ios
spec.source = { :git => 'https://github.com/cherrylabstech/asista-sdk-ios.git', :tag => spec.version }
spec.swift_version = '5.0'
spec.ios.deployment_target = '8.0'
spec.static_framework = true
spec.ios.vendored_frameworks = 'AsistaSupport/AsistaCore.framework'
end
-> AsistaCore (1.0.0)
- ERROR | [iOS] unknown: Encountered an unknown error (Pod::DSLError
/Library/Ruby/Gems/2.6.0/gems/cocoapods-core-1.8.4/lib/cocoapods-core/specification.rb:808:in `rescue in _eval_podspec'
....
...
We ran into this issue when we try creating a release and publishing a library. This error occurs when you are trying to run pod spec lint or pod repo push. The error says "DSLError" and doesn't give much information on what is causing it. I found little help online and some places they say, there could be a syntax error in the podspec file. We didn't have any in our podspec. However, this answer from stackoverflow gave me some direction https://stackoverflow.com/a/64779582
It looks like while making a release for one SDK/library, the pod spec lint and pod repo push validates all the podspecs in the folder besides the ones you ran. I don't know how that works internally. You should look for the following scenarios to identify the issue:
If there are other podspecs for capabilities that have different tags(Example: ABC.podspec pointed to source tag 1.0.0-ABC and XYZ.podspec pointed to source tag 2.0.0-XYZ)
Multiple podspecs have dependencies on different versions of the same module(Example: Module1.podspec depends on Module 5 version 10.0.0 and Module2.podspec also depends on Module 5 but on the version 11.0.0).
Syntax errors in any of the podspecs
If you come across either or both 1 & 2, it could be a potential cause for the DSLError.
When you run into this issue, make sure you look for and update the following:
All podspecs to have pointed to one source tag
All dependencies on a module pointed to one version of it in each capability.
Fix the sytanx errors.
This issue will go away or reduce significantly when the SDK libraries can be separated into their repositories instead of all in one repository, or perhaps even by keeping each podspec in their own individual folder.

iOS file patterns: The `source_files` pattern did not match any file

I am trying to create a CocoaPod and when I try pod lib lint there's an error about ERROR | [iOS] file patterns: Thesource_filespattern did not match any file.
I am trying to follow BlinkingLabel pod as an example and using Gitlab for storage of my .git . I tagged it successfully 1.0.0 and it worked for it.
I used my CocoaPod in Example for Pod and its working but I got the error:
Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.5
-> BlinkingLabel (1.0.0)
- ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.
- NOTE | xcodebuild: note: Using new build system
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Constructing build description
- NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')
[!] BlinkingLabel did not pass validation, due to 1 error.
You can use the `--no-clean` option to inspect any issue.
My source_file prop is:
s.source_files = 'BlinkingLabel/Classes/**/*'
But I've tried it with:
s.source_files = "BlinkingLabel/**/*"
s.source_files = 'BlinkingLabel/BlinkingLabel.swift'
s.source_files = 'BlinkingLabel/Classes/**/*.{h,m,c}'
No one has worked for me in lint.
And there's a strange thing.
In the article and examples it recommended to use with BlinkingLabel/Classes/**/* but there's nothing any directory as named Classes in BlinkingLabel, I guess because of new update of CocoaPod or maybe something is different in new CocoaPod. Can you explain this?
And how to solve this problem for pod lib lint at all?
Edit: I've searched over stackoverflow but nothing work for me.
Thanks in advance.
For anyone who stuck at - ERROR | [iOS] file patterns: Thesource_filespattern did not match any file., do not use source_files like below.
s.source_files = 'BlinkingLabel/Classes/**/*'
Use it with your inner directory name and exact file type.
For example if you have a Handler.swift file it must be.
s.source_files = 'Classes/**/*.swift'
If you have any .c file in your pod project that used
s.source_files = 'Classes/**/*.c'
or you can mix it with different file types.
Further I realized that the you must not trust to Classes directory.
You can create a Sources directory and can add all your source files into it and then you can try it with
s.source_files = 'Sources/**/*.swift'
This is the exact solution for me.
I hope it helps for anyone who stuck at.
I regret to ask the question.
It worked now.
s.source_files = 'BlinkingLabel/Classes/**/*'
I've not changed anything but it worked. That's strange.
You need to make sure that you have your files and source_files is appointed to that folder, and then check lint locally
pod lib lint YPlayer.podspec
if all ok, then you can push to cocoapods
pod trunk register email#domain.com 'Your Name' --description='Senior ios developer'
pod trunk push YPlayer.podspec
if it that failed again because of source_files then you need to make new tag, and need to push podspec file and your code relatively, because pod trunk push will check your your code using tag on git not locally like pod lib lint YPlayer.podspec

Private Swift Pod with ObjC static libraries

I am trying to create a private pod that ships with two static libraries.
Source of the pod is in swift however it depends upon two third party static libraries on which I have no control.
Linting my podspec, I get the following error just for the second lib (with a modulemap)
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
- ERROR | xcodebuild: TestKit/TestKit/SSAIPolicy.swift:11:8: error: no such module 'SecondLib'
And, here is the source part of my podspec file:
spec.source_files = 'TestKit/*', 'Vendor/**/*.{h,modulemap}'
spec.vendored_libraries = 'Vendor/FirstLib/libService.a', 'Vendor/SecondLib/libManagement.a'
spec.pod_target_xcconfig = { 'OTHER_LDFLAGS' => '-ObjC' }
Note: I am able to use this framework just fine by compiling and dropping it manually in the main app
In case anyone needs to know, I got it working by changing 'Target Membership'
of header files in my library from 'Project' to 'Public'

Include Pod's Bridging-Header to Build Settings of Project's Target?

I created an objective-c pod with two files:
Source/SomeViewController.h
Source/SomeViewController.m
I also created a bridging header in the pod:
Source/Bridging-Header.h
with the content:
#import "SomeViewController.h"
My podspec looks like this:
Pod::Spec.new do |s|
s.name = 'TestLib'
s.version = '0.0.1'
s.license = 'MIT'
s.ios.deployment_target = '7.0'
s.source_files = 'Source/*.{h,m}'
s.requires_arc = true
s.xcconfig = { 'SWIFT_OBJC_BRIDGING_HEADER' => 'Source/Bridging-Header.h' }
end
I created a demo project did pod init and inserted my pod. Then after pod install I get the following output:
Installing TestLib 0.0.1 (was 0.0.1)
Generating Pods project
Integrating client project
[!] The `TestLibProject [Debug]` target overrides the `SWIFT_OBJC_BRIDGING_HEADER` build setting defined in `Pods/Target Support Files/Pods-TestLibProject/Pods-TestLibProject.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `TestLibProject [Release]` target overrides the `SWIFT_OBJC_BRIDGING_HEADER` build setting defined in `Pods/Target Support Files/Pods-TestLibProject/Pods-TestLibProject.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
When I open my TestLibProject.xcworkspace file I see that the pod was installed correctly but the bridging header from the pod is not installed correctly. I my Swift project I tried to do:
let vc: SomeViewController
This gives an error because the bridging header from the pod ist not installed.
How do I have to configure the podspec in order to get the bridging header of the pod being installed correctly?
Podspecs build frameworks, and frameworks cannot include bridging headers. If you want to import non-modular code into a Swift framework, you'll need to use a custom module map, instead, e.g. at MyLib/module.modulemap:
framework module MyLib {
umbrella header "MyLib.h"
// Load an SDK header, e.g. CommonCrypto.h
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
export *
module * { export * }
}
Once there, you can specify the custom module map both in your Xcode project (either as the MODULEMAP_FILE setting in an .xcconfig file, or as the Module Map File of your target's Build Settings.
Now, the final piece of the puzzle: the podspec. You need to set the module_map:
Pod::Spec.new do |s|
# …
s.module_map = 'MyLib/module.modulemap'
end
The above is how SQLite.swift distributes itself, both as a general framework and as a pod.
Edit: Seems like I missed the point of the original question, as was clarified in this thread. The OP wanted to use a pod framework's bridging header to automatically load itself into the installing project's Swift code. This isn't possible. Even if Swift frameworks did support bridging headers, they would only be able to load Objective-C/C code (i.e. private framework code) into the framework's Swift code.

Resources