Xcode, cocoapods + nib file, s.resources = ['*.{xib}'] not work - ios

I have one trouble.
I created simple project and in result have next files: ViewController.h, ViewController.m, ViewController.xib, ViewController.podspec and LICENSE.
Structure of ViewController.podspec:
Pod:: Spec.new do |s|
s.name = "ViewController"
s.version = "0.1.0"
s.summary = "Some text"
s.homepage = "setmypage"
s.license = 'MIT'
s.author = { "Oleksii" => "oleksii#site.com" }
s.source = { :path => "." }
s.platform = :ios
s.requires_arc = true
s.source_files = '*.{h,m,xib}'
s.resources = ['*.{xib}']
end
I created simple new project and added folder with Pod.
after I did pod lib lint for my Pod
and do pod install this pod.
Structure Podfile:
platform :ios
pod "ViewController", :path => "testPod/"
pod 'ViewController'
Ok. I had project with my Pod. But when I'd tried to Build my project I received
Unable to run command 'StripNIB ViewController.nib' - this target might include its own product.
What should I do?

I had the same problem. You should not include the xib in the source_files parameter in your podspecs:
s.source_files = '*.{h,m,xib}'
s.resources = ['*.{xib}']
My podspecs was a little bit different than yours because by default cocoapod version 0.39 was setting a wildcard in the source_files which was obviously too inclusive, even if my xib were included as resources (resource_bundle):
s.source_files = 'Pod/Classes/**/*.{h,m}'
s.resource_bundles = {
'MyPodBundle' => ['Pod/Classes/**/*.xib']
}
So make sure you do not include your xib as source_files

The possible cause for this your listing your product's target under target dependencies. In xcode select your target and under Build Phases look at the Dependencies list your products target should not be listed there.
Also check your Bundle Resources and Link Binary with Libraries you can't have your product listed there.

Related

How to configure build setting of Xcode project through podspec

I have project developed by using plugins. So to add any new feature we create new plugin add it to main project after develop and tested. Every plugin has its own podfile and podspec. So I want to add quantumgraph pod to one of my plugin that named I GraphIntegrationPlugin.
Below is my podspec of GraphIntegrationPlugin:
Pod::Spec.new do |s|
s.name = "GraphIntegrationPlugin"
s.version = '0.1.1'
s.summary = "GraphIntegrationPlugin plugin.
DESC
s.homepage = "https://abc:8fqTzT2v7UXAwu6RE6CV#bitbucket.org/GraphIntegrationPlugin-ios.git"
s.license = 'MIT'
s.author = { "Aabc dd” => “abc#gmail.com" }
s.source = { :git => "https://abc:8fqTzT2v7UXAwu6RE6CV#bitbucket.org/GraphIntegrationPlugin-ios.git", :tag => s.version.to_s }
s.ios.deployment_target = "10.0"
s.platform = :ios, '10.0'
s.requires_arc = true
s.swift_version = '5.1'
s.frameworks = 'UserNotifications', 'UIKit', 'Foundation', 'UserNotificationsUI'
s.source_files = 'PluginClasses/**/*.{swift,h,m}'
s.resources = 'Resources/**/*.{storyboard,xib,xcassets,png,plist}'
s.public_header_files = 'Pods/**/**/*.h'
# Public frameworks
s.dependency 'quantumgraph'
s.xcconfig = {
'OTHER_LDFLAGS' => '-objc -ObjC',
'OTHER_CFLAGS' => '-fembed-bitcode',
'ENABLE_BITCODE' => 'YES',
'SWIFT_VERSION' => '5.1',
'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES',
'FRAMEWORK_SEARCH_PATHS' => '$(inherited) "${PODS_ROOT}"/**',
'LIBRARY_SEARCH_PATHS' => '$(inherited) "${PODS_ROOT}"/**',
'HEADER_SEARCH_PATHS' => '$(inherited) "${PODS_ROOT}"/Headers/Public'
}
end
After compile main project including this GraphIntegrationPlugin generate following project directory structure:
MainProject:
- support files
- Resources
- Classes, etc.
Pod:
- Pods
--quantumgraph
- iOS-sdk
- QGSdk.h
- QGInbox.h
- Frameworks
- libQGSdk.a
- Support Files
- quantumgraph.xcconfig
--GraphIntegrationPlugin
-xyz.swift
-support files
- GraphIntegrationPlugin.modulempa
- GraphIntegrationPlugin.xcconfig
- GraphIntegrationPlugin.dummy.m
- GraphIntegrationPlugin-Info.plist
- GraphIntegrationPlugin.prefix.pch
- GraphIntegrationPlugin.umbrella.h
After successfully generate project when I try to add import QGSdk to xyz.swift it throws error module not found. to fix this I did following manual changes to build setting of GraphIntegrationPlugin.
I added libQGSdk.a to Framework and linked libraries in General of GraphIntegrationPlugin Target.
In GraphIntegrationPlugin.umbrella.h I added #import QGSdk.h
I added QGSdk.h to GraphIntegrationPlugin target and Target Membership made it public.
After this, error disappears and I am able to access all methods and variable of QGSdk to my xyz.swift.
But unfortunately I can not push this manual changes of build setting to Git or our architecture does not support this. Hence all above three manual build setting changes I want to do through podspec. I tried every possible solution to write podspec in such a way that it should configure build settings of GraphIntegrationPlugin as per my expected way but unable to do this.
What changes I need to do to podspec so make QGSdk.h header available in my Swift classes of GraphIntegrationPlugin? I have this link with me BJ Homer but it did not fulfil my requirement of creating podspec.
Has tried setting the static framework to true, in the Podspecs?
s.static_framework = true
I use this setting for the same situation:
s.public_header_files = [
"MVVMRools/MVVMRools.h",
"MVVMRools/MVVMRools-Briging-Header.h",
"MVVMRools/Another.h"]

Using the framework from one target as a pod in another target locally

I'm having trouble using a framework I wrote in other targets (the same project) using modular imports. I'm using Cocoapods. I'm getting Could not build module: errors while trying to import the module using modular imports (#import CMPComapiFoundation;). I attach a link to the repo for more information.
I did try both local (:path =>) and remote (:git =>) ways of pulling the SDK in Podfile, none of which seems to work. It's worth noting that if added via Cocoapods in a separate project, the code compiles and the SDK can be imported.
SDK's .podspec file:
Pod::Spec.new do |s|
s.name = 'CMPComapiFoundation'
s.version = '1.2.2'
s.license = 'MIT'
s.summary = 'Foundation library for connecting to and consuming COMAPI services'
s.description = <<-DESC
# iOS SDK for Comapi
Client to connect your iOS application with [Comapi](http://comapi.com/) services and add it as a channel to our cloud messaging platform. Written in Objective-C.
For more information about the integration please visit [the website](http://docs.comapi.com/reference#one-sdk-ios).
DESC
s.homepage = 'https://github.com/comapi/comapi-sdk-ios-objc'
s.author = { 'Comapi' => 'support#comapi.com' }
s.source = { :git => 'https://github.com/comapi/comapi-sdk-ios-objc.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/comapimessaging'
s.ios.deployment_target = '10.0'
s.requires_arc = true
s.source_files = 'Sources/**/*.{h,m}'
s.resources = []
s.dependency 'SocketRocket'
end
And here's the Podfile I'm using for the entire project:
platform :ios, '10.0'
use_frameworks!
def shared
pod 'CMPComapiFoundation', :path => '/Users/dominik.kowalski/Documents/comapi-sdk-ios-objc'
pod 'JWT'
end
target 'CMPComapiFoundation' do
pod 'SocketRocket'
end
target 'CMPComapiFoundationTests' do
shared
end
target 'ComapiFoundationSample' do
shared
end
target 'ComapiFoundationSample-Swift' do
shared
pod 'SnapKit'
end
I expect the test and sample targets to import the modules and compile the code.
Okay I managed to fix it myself. Some header files were missing Target membership, but Xcode gave me misleading hints.

How to create podspec file for pods with right path to Localizable assets in iOS

In my project I have three Pods and each have their own localizable assets under Resources/Pod/Assets folder. However the localizations for my main project files work but localization for pods didn't work.If I place all my pods localization assets into my main project folder , then everything works, but it is not the case I'm looking for.I need to have my pods store their own localizable assets.
Here is my podspec for my pods:
Pod::Spec.new do |s|
s.name = "MyPod"
s.version = "0.1"
s.summary = "A short description of MyLib."
s.platform = :ios, '8.0'
s.requires_arc = true
s.source_files = 'Pod/**/*.{h,m}'
s.resource_bundles = {
'MyPod' => ['Pod/**/*.{caf,xib,mp4,mp3,m4a,wav,plist,atlas}',
'Pod/Assets/pngs/**/*.{png,jpg}',
'Pod/Assets/fr-CA.lproj/*.strings',
]
}
s.prefix_header_file = 'MyPodPrefixHeader.pch'
s.dependency 'MyOtherPod'
end
I also tried
'Pod/Assets/*.{lproj}'
and
'Pod/Assets/*.{lproj}/*.strings'
Everytime I change the podspec I do pod install
But none of them worked. Pod localizable assets are not loading in my project.
ANy ideas where I could have gone wrong ?

Empty podspec for vendored_framework (The spec is empty...)

I've successfully compiled a framework using Cocoapods Packager
When attempting to lint the podspec that contains that framework, I'm getting the following error:
ERROR | File Patterns: The spec is empty (no source files, resources, resource_bundles, preserve paths, vendored_libraries, vendored_frameworks, dependencies, nor subspecs).
My podspec is simple and looks like this:
Pod::Spec.new do |s|
s.name = 'MyFramework'
s.module_name = 'MyFramework'
s.version = '0.0.1'
s.summary = 'Summary goes here...'
s.license = 'MIT'
s.homepage = 'http://GITHUB_ACCOUNT.com'
s.frameworks = ["CoreData", "CoreGraphics", "CoreImage", ...more frameworks]
s.requires_arc = true
s.source = {
:git => "https://github.com/GITHUB_ACCOUNT/MyFramework.git",
:tag => s.version.to_s
}
s.ios.platform = :ios, '9.0'
s.ios.preserve_paths = 'MyFramework.embeddedframework/MyFramework.framework'
s.ios.public_header_files = 'MyFramework.embeddedframework/MyFramework.framework/Versions/A/Headers/*.h'
s.ios.vendored_frameworks = 'MyFramework.embeddedframework/MyFramework.framework'
end
The basic format of the podspec is actually generated by Cocoapods-Packager. I've ensured that the following paths in the podspec all point to the expected files:
s.ios.preserve_paths = 'MyFramework.embeddedframework/MyFramework.framework'
s.ios.public_header_files = 'MyFramework.embeddedframework/MyFramework.framework/Versions/A/Headers/*.h'
s.ios.vendored_frameworks = 'MyFramework.embeddedframework/MyFramework.framework'
Running pod spec lint --verbose first tells me that ** BUILD SUCCEEDED **', but then generates the error.
Using the framework in a project via pod update works! But I can't get the pod to lint, so I'll never be able to submit it to the Cocoapods repo.
Note that all of the silly paths in the podspec I've pasted here ('http://GITHUB_ACCOUNT.com') are just placeholders and are valid paths in my actual podspec.
I'm using cocoapods 0.39.0.
Any ideas?
Found out what was wrong here.
s.ios.platform = :ios, '9.0'
means that the linter will build for ALL platforms.
The podspec as created by Cocoapods-Packager initially has this:
s.platform = :ios, '9.0'
s.ios.platform = :ios, '9.0'
At some point I inadvertently deleted the first line, I guess. At any rate, the absence of s.platform tells the linter that you want to test on all platforms.
See valid = spec.available_platforms.send(fail_fast ? :all? : :each) do |platform| here
I never expected to be testing on all platforms, only iOS. It turns out that the linter was failing while testing for watchOS, which I don't care about...
Hopefully this will help someone who makes the same mistake!

Podspec validates but files are not installed

I'm in the process of writing my very first pod spec, and while I have managed to write a spec that passes validation and pod install seems to install the pod OK the actual source-files are nowhere to be found in my workspace. This is my podfile:
platform :ios, '7.0'
xcodeproj 'NORLabelNodeiOStest'
pod 'NORLabelNode', :path => '~/Programmering/Development/NORLabelNodePodSpec'
pod 'AFNetworking'
As you can see the NORLabelNode pod is installed through a local version of the podspec which looks like this:
Pod::Spec.new do |s|
s.name = "NORLabelNode"
s.version = "0.9.2"
s.summary = "Extension of Apple's SKLabelNode. Allowing multiple lines through the use of \n in the text-string. "
s.description = <<-DESC
Behaves like an ordinary SKLabelNode with the one difference that adding newline characters to the text- property actually adds line-breaks. This is achieved by creating SKLabelNodes as child-nodes, but keeping these as part of the internal (private) logic.
DESC
s.homepage = "https://github.com/nickfalk/NORLabelNode.git"
s.license = 'MIT'
s.author = { "T. Benjamin Larsen" => "benjamin.larsen#noreagle.no" }
s.source = {
:git => "https://github.com/nickfalk/NORLabelNode.git",
:tag => 'v0.9.2'
}
s.social_media_url = 'https://twitter.com/noreagle'
s.platform = :ios, '7.0'
s.ios.deployment_target = '7.0'
s.osx.deployment_target = '10.9'
s.requires_arc = true
s.frameworks = 'SpriteKit'
s.source_files = 'NORLabelNode.{h,m}'
end
Running pod install gives no indication that anything has gone amiss:
Analyzing dependencies
Fetching podspec for `NORLabelNode` from `~/Programmering/Development/NORLabelNodePodSpec`
Downloading dependencies
Installing AFNetworking (2.2.3)
Installing NORLabelNode (0.9.2)
Generating Pods project
Integrating client project
[!] From now on use `NORLabelNodeiOStest.xcworkspace`.
The AFNetworking pod installs the files as expected, but my own NORLabelNode does not. Anyone?
As you can see the NORLabelNode pod is installed through a local version of the podspec which looks like this
That's not how the path option works. It expects a path to the project itself, not the spec.
From the docs:
Using this option CocoaPods will assume the given folder to be the root of the Pod and will link the files directly from there in the Pods project.
If you would like to just use your spec without adding it to the master repo you can create your own repo of specs (docs). Or just place your spec in the correct folder structure in ~/.cocoapods/repos/master

Resources