Private CocoaPod Spec with Dependency Cannot Find Dependency - objective-c

I'm trying to deploy a private CocoaPod, and I'm running into a perplexing issue with my framework's dependency graph. I cannot get my code to find a necessary class from one of its dependencies - RestKit, to be specific.
I first ran pod lib create to create the framework, then added RestKit as a dependency of the private CocoaPod in its .podpsec file. Everything seemed to be working fine until I referenced one particular class in RestKit, which it cannot seem to find unless I use an #import statement.
I've tried all of the following include's, and none of them work:
#import <RestKit/RestKit.h>
#import <RestKit/ObjectMapping.h>
#import <RestKit.h>
#import <ObjectMapping.h>
#import "RestKit.h"
#import "ObjectMapping.h"
The only one that does work is #import RestKit.ObjectMapping. However, using this import/include statement causes pod lib lint to fail as it can't find RestKit. I'm a bit stuck as to what else to try here. I've remade the podspec project already, and I've tried all the includes. Has anyone else ran into this issue?
Edit:
Below is my podspec.
Pod::Spec.new do |s|
s.name = "MyAPI"
s.version = "0.1.4"
s.summary = "My summary here."
s.description = <<-DESC
My description here.
DESC
s.homepage = "http://example.com"
s.license = 'None'
s.author = { "Sean Olszewski" => "sean#somewebsite.com" }
s.source = { :git => "ssh://username#myprivateserver/path/to/private/pod/repo", :tag => s.version.to_s }
s.platform = :ios, '7.0'
s.requires_arc = true
s.source_files = 'Pod/Classes/**/*'
s.resource_bundles = {
'MyAPI' => ['Pod/Assets/*.png']
}
s.public_header_files = 'Pod/Classes/**/*.h'
s.dependency 'RestKit', '~> 0.25.0'
s.dependency 'RKValueTransformers'
end

You should specify a version and a development target for your Pod.
s.ios.deployment_target = '7.0'
s.platform = :ios, '7.0'
Also you will have to change the import statement in your code, as it will be interpreted as a module (use_frameworks! in the pod file ), that's why you can't use #import anymore.
If you run into the 'non modular include' you will the to set the property in your Podspec:
s.xcconfig = { 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES'}

Related

How to create podspec file for a React Native Library

I am writing my components in React Native using react-native cli and am damn frustrated and confused about configuring it to be consumed as a library. Here's how the react native folder structure looks like:
src
ios
build
projectName.xcodeproj
projectName.xcodeworkspace
PodFile
PodFile.lock
...
android
index.js
...
when I open the xcode and build the project everything works fine as expected, now here's the thing. My React Native code sits into a git repository (Repo-A) which is different from an ios-repository (Repo-B) which contains collection of lot of independent pods.
All I want is to configure my project (Repo-A) MyApp to be consumed by Repo-B. I want to understand two syntax:
How do I add podSpec file in my Repo-A so that it points to ios directory so that it could be picked up by other repositories (in this case Repo-B).
In order to include the podfile in a specific repo (Repo-B in this case), all I need to do is the below snippet or something else? [Also how does podFile get access to these private repositories?]
Here's how I would like to consume it:
pod 'MyApp', :git => 'https://github.com/<username>/my-app', :branch => 'main'
Someone please help me understanding how can I achieve this? (Connecting the podFiles).
Additionally, one more thing I would like to know is how the versioning works? Like lets say I make some updates to my codebase, if I push it all to main and rebuild the Repo-B would that be sufficient to update changes in app or should I be using tags and create podSpec for each changes?
I can answer at least part of your question:
In Repo-A, create a podspec file with the same name as your library: my-library-name.podspec. Add this code:
require "json"
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_version = '2021.06.28.00-v2'
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
Pod::Spec.new do |s|
s.name = "my-library-name"
s.version = package["version"]
s.summary = package["description"]
s.homepage = package["homepage"]
s.license = package["license"]
s.authors = package["author"]
s.platforms = { :ios => "10.0" }
s.source = { :git => "https://github.com/<username>/my-app", :tag => "#{s.version}" }
s.source_files = ['ios/']
s.dependency "React-Core"
# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-Codegen"
s.dependency "RCT-Folly", folly_version
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end
The s.source_files points to the ios directory so that it can be referenced by other repositories.
Documentation on sourcing other repos in podspec: https://guides.cocoapods.org/syntax/podspec.html#source

Podspec The pattern INCLUDES header files that are not listed in source_files

I am trying to create a Cocoapod. But when I run pod lib lint I get the below error:
MyCoolProject (1.0.0)
- ERROR | [iOS] public_header_files: The pattern includes header files that are not listed in source_files
Then it list out all my .h files. (Some removed for brevity)
/Users/myusername/Documents/GitHub/MyCoolProject/Pod/Classes/Objective-C/MyCoolProject.h,
/Users/myusername/Documents/GitHub/MyCoolProject/Pod/Classes/Objective-C/MyCoolProjectConstants.h,
/Users/myusername/Documents/GitHub/MyCoolProject/Pod/Classes/Objective-C/MyCoolProjectEnums.h,
/Users/myusername/Documents/GitHub/MyCoolProject/Pod/Classes/Objective-C/MyCoolProjectMacros.h,
/Users/myusername/Documents/GitHub/MyCoolProject/Pod/Classes/Objective-C/MyCoolProject_.h,
/Users/myusername/Documents/GitHub/MyCoolProject/Pod/Classes/Objective-C/UIView+MyCoolProjectPrivate.h,
/Users/myusername/Documents/GitHub/MyCoolProject/Pod/Classes/Objective-C/UIViewController+MyCoolProject.h
I have spent 2 days and found 0 information that helps me understand and correct the error. Can anyone shed some light on what I might be doing wrong?
Here is my podspec file
Pod::Spec.new do |s|
s.name = "MyCoolProject"
s.version = "1.0.0"
s.summary = "Color Framework for iOS (Obj-C & Swift)"
s.homepage = "https://github.com/myusername/MyCoolProject"
s.license = { :type => "MIT", :file => "LICENSE.md" }
s.author = "My Name"
s.platform = :ios
s.ios.deployment_target = '8.0'
s.source = { :git => "https://github.com/myusername/MyCoolProject.git",
:tag => s.version.to_s }
s.public_header_files = 'Pod/Classes/Objective-C/**/*.h'
s.frameworks = 'UIKit', 'QuartzCore', 'CoreGraphics'
s.default_subspecs = 'Default'
s.subspec 'Default' do |ss|
ss.source_files = 'Pod/Classes/Objective-C/**/*.{h,m}'
end
s.subspec 'Swift' do |ss|
ss.ios.deployment_target = '8.0'
ss.source_files = 'Pod/Classes/Swift/MyCoolProjectShorthand.swift'
ss.dependency 'MyCoolProject/Default'
end
end
As you can see from my screenshot all the files are there:
Does moving the public_header_files declaration into the Default subspec make a difference? Or moving source_files to the outer scope?
I suspect that CocoaPods is checking the files for Swift subspec before it processes its dependencies.

Specifying frameworks and weak_frameworks in CocoaPods podspec don't seem to work

I specified frameworks ad weak_frameworks for my private pod but after installing it via pod install, I am not seeing AdSupport or WebKit appearing anywhere in the project settings.
Should it appear under Build Phases -> Link Binary with Libraries or Build Settings -> Linker Flags? What's the difference between the two?
Pod::Spec.new do |s|
s.name = 'Analytics'
s.version = '1.0.0'
s.summary = 'Analytics SDK'
s.description = <<-DESC
Analytics SDK
DESC
s.homepage = 'https://github.com/author/analytics-ios'
s.license = ''
s.author = { 'Author' => 'Email' }
s.source = { :git => 'https://github.com/author/analytics-ios.git', :tag => s.version.to_s }
s.vendored_frameworks = 'Pods/Assets/Analytics.framework'
s.ios.deployment_target = '9.0'
s.frameworks = 'AdSupport'
s.weak_frameworks = 'WebKit'
end
You can find the reference to those frameworks on your respective .xcconfig file associated to your target. In the Pods folder within your main Xcode project structure.

Unable to find a specification for [PUBLIC POD] depended upon by [PRIVATE POD]

I'm creating a private pod to handle all common code used in my projects. This private pod has several subspecs on his podspec and one of them depends of a well known public pod: AFNetworking.
On my podspec I have this
Pod::Spec.new do |s|
s.name = "NAME"
s.version = "0.0.1"
s.summary = "SUMMARY"
s.description = "DESCRIPTION"
s.homepage = "https://myhomepage.com"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Me" => "me#myemail.com" }
s.platform = :ios, "8.0"
s.source = { :git => "https://repositorywithmyprivatepodcode", :tag => s.version }
s.subspec 'Core' do |cs|
cs.source_files = "Source/Core/**/*.{h,m}"
end
s.subspec 'Resized' do |rs|
rs.source_files = "Source/Resized/**/*.{h,m}"
rs.dependency 'NAME/Core'
rs.dependency 'AFNetworking' , '~> 3.0'
end
s.subspec 'UI' do |us|
us.source_files = "Source/UI/**/*.{h,m}"
end
end
I have this code on the Podfile of the project where I'm trying to use the
"Resized" subspec
source 'https://repositorywithmyprivatepodcode'
target 'TestProject' do
pod 'Square1/Resized'
end
But I'm getting this error when running pod install
[!] Unable to find a specification for `AFNetworking` depended upon by `Square1/Resized`
What I'm missing here?
Well, my problem was that I didn't include the Cocoapods master repository on my project's Podfile.
The official CocoaPods source is implicit. Once you specify another
source, then it will need to be included.
So I changed my Podfile to include it
source 'https://bitbucket.org/square1mobileteam/square1-specs'
source 'https://cdn.cocoapods.org/'
And it works.

Lint Fail for Cocoapods

I have an Objective-C Library and I am trying to update the podspec to cocoapods. When I do the "pod spec lint" command I get the following error:
[!] The spec did not pass validation, due to 1 error.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
Here is my podspec file:
Pod::Spec.new do |s|
s.name = "OSwitch"
s.version = "0.2.0"
s.license = { :type => "MIT", :file => "LICENSE" }
s.summary = "OSwitch is a customisable switch control writen in Objective C."
s.homepage = 'https://github.com/OyaSaid/OSwitch'
s.source = { :git => 'https://github.com/OyaSaid/OSwitch.git', :tag => s.version.to_s }
s.platform = :ios, "7.0"
s.ios.frameworks = ['UIKit', 'Foundation']
s.source_files = 'OSwitch/Classes/**/*.{h,m}'
s.requires_arc = true
end
Why does this show when I have an objective C library. And how do I fix this?
Thanks
It shows that because you're able to use both swift and Objc languages in your pod.
Just run the following command in the terminal:
`echo "2.3" > .swift-version`
Replace "2.3" with your current Swift version in XCode, if you're on 3.1 for example replace it with "3.1". It will create a swift version file in your pod-project folder. And then you can run the lint command to validate your podspec.