Error using Apple frameworks in my CocoaPod podspec? - ios

I have a cross platform library that I'm trying to push to CocoaPod, but the it is failing on the podspec validation. The error I get is:
ERROR | xcodebuild: Returned an unsuccessful exit code. You can use --verbose for more information.
ERROR | xcodebuild: MyPod/Sources/CLKComplicationServer.swift:10:8: error: no such module 'ClockKit'
I tried adding the frameworks to my podspec, but it is still not accepting. Here is what my podspec looks like:
Pod::Spec.new do |s|
...
s.ios.deployment_target = "8.4"
s.watchos.deployment_target = "2.0"
s.tvos.deployment_target = "9.0"
s.requires_arc = true
s.ios.framework = 'AVFoundation'
s.watchos.framework = 'ClockKit'
s.source_files = "Sources/**/*.{h,swift}"
end
What am I doing wrong? I'm having the same issue with AVFoundation. I tried adding both to my header file, but ClockKit is not recognized.

Related

Xcode Swift CocoaPods pod spec lint Fails on Embed Pods Frameworks

I'm getting the following error when trying to run pod spec lint --verbose:
sent 1312397 bytes received 106 bytes 2625006.00 bytes/sec
total size is 1311832 speedup is 1.00
/var/folders/3d/v0m_90ty4mg1opbynpnjjvzh2010gm/T/CocoaPods-Lint-20181015-62030-oljqd-MySwiftPackage/Pods/Target Support Files/Pods-App/Pods-App-frameworks.sh: line 104: EXPANDED_CODE_SIGN_IDENTITY: unbound variable
Command PhaseScriptExecution failed with a nonzero exit code
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks /Users/myuser/Library/Developer/Xcode/DerivedData/App-loplmnuztwibrzfqgadqoxucytrz/Build/Intermediates.noindex/App.build/Release/App.build/Script-09EB8340PON5K18DNW0C63DQ.sh
(1 failure)
Testing with `xcodebuild`.
-> MySwiftPackage (0.1.0)
- WARN | summary: The summary is not meaningful.
- WARN | description: The description is shorter than the summary.
- WARN | url: The URL (https://github.com/fishcharlie/MySwiftPackage) is not reachable.
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Planning build
- NOTE | xcodebuild: note: Constructing build description
- NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file. (in target 'App')
- WARN | xcodebuild: MySwiftPackage/MySwiftPackage/ViewControllers/Shared/MyFirstViewController.swift:102:37: warning: conditional cast from 'UIViewController' to 'MyViewController' (aka 'UIViewController') always succeeds
- WARN | xcodebuild: MySwiftPackage/MySwiftPackage/ViewControllers/Shared/MySecondViewController.swift:145:37: warning: conditional cast from 'UIViewController' to 'MyViewController' (aka 'UIViewController') always succeeds
- ERROR | [OSX] xcodebuild: Returned an unsuccessful exit code.
Analyzed 1 podspec.
[!] The spec did not pass validation, due to 1 error and 5 warnings.
I know I have a few warnings that I can clean up. But there is only one error that I'm getting, which is - ERROR | [OSX] xcodebuild: Returned an unsuccessful exit code.. And above that it says that Embed Pods Frameworks was the cause of failure.
Not quire sure how to debug this since I can build and run the example projects in Xcode just fine.
Below I have attached my Podspec as well.
Pod::Spec.new do |s|
s.name = 'MySwiftPackage'
s.version = '0.1.0'
s.summary = 'A short description of MySwiftPackage.'
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://github.com/fishcharlie/MySwiftPackage'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'fishcharlie' => 'fishcharlie.code#gmail.com' }
s.source = { :git => 'https://github.com/fishcharlie/MySwiftPackage.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/char_fish'
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.11'
s.swift_version = '4.2'
s.source_files = 'MySwiftPackage/Classes/**/*', 'MySwiftPackage/ViewControllers/Shared/**/*'
s.ios.source_files = 'MySwiftPackage/ViewControllers/iOS/**/*'
s.osx.source_files = 'MySwiftPackage/ViewControllers/macOS/**/*'
s.resources = 'MySwiftPackage/Assets/**/*.{ttf,xcassets}'
s.dependency 'Alamofire', '4.7.3'
s.dependency 'Bond', '6.10.2'
s.ios.dependency '1PasswordExtension', '1.8.5'
end
Any ideas on how to fix/debug this?
The error should be about
line 104: EXPANDED_CODE_SIGN_IDENTITY: unbound variable
The solution (as stated in Issue 7708 on github/Cocoapods ) should be to add the following User-Defined Settings to project:
EXPANDED_CODE_SIGN_IDENTITY="-"
EXPANDED_CODE_SIGN_IDENTITY_NAME="-"`
Try adding the flag --no-clean. This flag makes lint leave the build directory
intact for inspection
so you can debug that build failure in a workspace which may be more familiar and give you more information.
Looks like they fixed this for xcode 10 in pr github.com/CocoaPods/CocoaPods/pull/7720, you could try upgrading to 1.6.0, or downgrading xcode to 9.4.

Where storyboards should be included in a pod project?

I'm trying to generated a Pod with some graphics into a storyboard.
Well, my issue is the next.
When I try to run
pod spec lint --verbose
I get the next error:
The following build commands failed:
ComipileStoryboard MyProject/Example/Base.lproj/Main.storyboard
- ERRRO | [iOS] xcodebuild: Returned an unsuccessful exit code.
Where I should add the storyboards files?
Anything other than source files will go in resources or resource-bundles
Pod::Spec.new do |spec|
spec.name = 'YOUR_LIB_NAME'
spec.version = '1.0'
spec.source_files = 'YOUR_LIB_NAME/*'
spec.resource_bundles = {
'YOUR_LIB_NAME' => ['YOUR_LIB_NAME/YOUR_PATH_TO_STORYBOARD/*.storyboard']
}
end

Building a Cocoapod with both Swift and Objective-C: How to Deal with Umbrella Header Issues?

I have an existing Xcode framework, that uses both Swift and Objective-C, that I'm trying to get working as a Cocoapod. My steps so far are:
1) I used pod lib create SMCoreLib to initialize a new folder (https://guides.cocoapods.org/making/using-pod-lib-create.html).
2) I copied the Swift and Objective-C code from my framework into the SMCoreLib/Classes folder in this newly initialized pod folder. I also dragged this code into the relevant group in _Pods.xcodeproj.
3) I made some changes to the .podspec file for my project. It's as follows (note that the Github repo hasn't been updated yet with these changes; I can do that if someone wants):
Pod::Spec.new do |s|
s.name = 'SMCoreLib'
s.version = '0.0.2'
s.summary = 'Spastic Muffin Core Library for iOS'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
Objective-C and Swift classes to support Spastic Muffin code.
DESC
s.homepage = "https://github.com/crspybits/SMCoreLib.git"
s.license = { :type => "GPL3", :file => "LICENSE.txt" }
s.author = { "Christopher Prince" => "<snip>" }
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/crspybits/SMCoreLib.git", :tag => "#{s.version}" }
s.ios.deployment_target = '8.0'
s.source_files = 'SMCoreLib/Classes/**/*'
s.resources = "SMCoreLib/Assets/**"
# s.resource_bundles = {
# 'SMCoreLib' => ['SMCoreLib/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
s.requires_arc = true
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
s.dependency 'AFNetworking'
s.dependency 'HPTextViewTapGestureRecognizer', '~> 0.1'
s.dependency 'Reachability'
end
My problem is that I get failures both trying to build the Example Xcode project and trying to lint the pod. Building the Example Xcode project, I get the following errors:
From the command line, when I do:
pod lib lint --allow-warnings --verbose --no-clean
I get the following errors:
- NOTE | [iOS] xcodebuild: <module-includes>:2:9: note: in file included from <module-includes>:2:
- ERROR | [iOS] xcodebuild: /Users/chris/Library/Developer/Xcode/DerivedData/App-bhqthebvswpzxeesjidsqpmmwovu/Build/Products/Release-iphonesimulator/SMCoreLib/SMCoreLib.framework/Headers/SMCoreLib-Swift.h:103:9: error: 'SMCoreLib/SMCoreLib.h' file not found
- NOTE | [iOS] xcodebuild: <unknown>:0: error: could not build Objective-C module 'SMCoreLib'
The problem appears to be that in the automatically generated SMCoreLib-Swift.h Generated Interface Header, the SMCoreLib.h umbrella header cannot be found. I would greatly appreciate any suggestions.
I have a hack fix for this problem. I'd like a better one. The fix is to put a SMCoreLib.h file at: SMCoreLib/Classes/SMCoreLib.h. The file contains the single line:
#import "SMCoreLib-umbrella.h"
The problem seems to be that the Generated Interface Header doesn't respect a name change for the umbrella header given in a module map. Cocoapods creates this module map and the name change. This hack fix is present in the Git repo for this project https://github.com/crspybits/SMCoreLib.git.

Unable to import AFNetworking dependency into Cocoapod

I'm trying to setup the podspec for my project and I keep getting this error when I run pod spec lint
➭ pod spec lint
-> BRECBathroomFinder (1.0.0)
- ERROR | [iOS] Returned an unsuccessful exit code. You can use `--verbose` for more information.
- ERROR | BRECBathroomFinder/BRECBathroomFinder/BBFOpenDataClient.swift:16:26: error: use of undeclared type 'AFHTTPRequestOperationManager'
- ERROR | [iOS] BRECBathroomFinder/BRECBathroomFinder/BBFOpenDataClient.swift:29:73: error: use of undeclared type 'AFHTTPRequestOperation'
- ERROR | [iOS] BRECBathroomFinder/BRECBathroomFinder/BBFOpenDataClient.swift:48:35: error: use of undeclared type 'AFHTTPRequestOperation'
- NOTE | [iOS] }, failure: { (operation: AFHTTPRequestOperation!, error: NSError!) -> Void in
- ERROR | [iOS] BRECBathroomFinder/BRECBathroomFinder/BBFOpenDataClient.swift:29:9: error: 'BBFOpenDataClient' does not have a member named 'GET'
Analyzed 1 podspec.
Here is my podspec. You'll notice at the bottom that my I've got .prefix_header_contents = "#import <AFNetworking/AFNetworking.h>" in there; so it doesn't make sense to me that it can't find the AFHTTPRequestOperation class.
Pod::Spec.new do |s|
s.name = "BRECBathroomFinder"
s.version = "1.0.0"
s.summary = "A pod that finds nearby BREC parks with restrooms"
s.description = <<-DESC
This is a project built on top of Baton Rouge's Open Data API. It uses a query to find parks with bathrooms.
The results can be sorted according to how close the parks are to a given location or the user's location.
DESC
s.homepage = "https://github.com/jmhooper/BRECBathroomFinder"
s.author = { "Jonathan Hooper" => "jon9820#gmail.com" }
s.license = 'MIT'
s.source = { git: "https://github.com/jmhooper/BRECBathroomFinder.git", tag: s.version.to_s }
s.platform = :ios, '8.0'
s.requires_arc = true
s.source_files = "BRECBathroomFinder/**/*"
s.dependency "AFNetworking", "~> 2.0"
s.frameworks = "CoreLocation"
s.prefix_header_contents = "#import <AFNetworking/AFNetworking.h>"
end
After a lot of frustration I finally figured it out.
In the file it was complaining about, I had to add a import AFNetworking line along with the rest of my Swift imports.
I did that and the podspec passed validation.

CocoaPods podspec lint failure - file not found

I'm trying to distribute my pod, but I'm having issues with it's validation.
When I'm trying to lint against my .podspec I'm getting:
- ERROR | [iOS] [xcodebuild] path/to/my/source/file.m:14:9: fatal error: 'KeyValueObjectMapping/DCKeyValueObjectMapping.h' file not found
I tried to preserve the path to their framework with different variations like
s.preserve_paths = 'KeyValueObjectMapping.framework/*'
or
s.preserve_paths = '${PODS_ROOT}/Vendor/KeyValueObjectMapping/KeyValueObjectMapping.framework'
& other variations but that way I'm getting one more error:
- ERROR | [iOS] The `preserve_paths` pattern did not match any file.
I also tried different other things which I saw on other issues like:
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/Vendor/KeyValueObjectMapping/KeyValueObjectMapping.framework"','FRAMEWORK_SEARCH_PATHS' => '"$(PODS_ROOT)/Vendor/KeyValueObjectMapping/*"' }
s.framework = 'KeyValueObjectMapping'
The project builds fine with Xcode5 & with xcodebuild with it's default setup, I'm getting this issue only when validating it for Cocoapods.
I was running into this issue trying to create a custom Podspec and add the RevMob and Heyzap SDKs as dependencies.
I kept getting the following error:
- ERROR | [iOS] [xcodebuild] MyProject/MyProjectSubDir/AnotherDir/CustomAd.h:10:9: fatal error: 'RevMobAds/RevMobAds.h' file not found
- ERROR | [iOS] [xcodebuild] MyProject/MyProjectSubDir/AnotherDir/FacebookController.m:18:9: fatal error: 'RevMobAds/RevMobAds.h' file not found
Then when I specified the FRAMEWORK_SEARCH_PATHS for RevMob, I would get the same error but for Heyzap's SDK.
The solution for me was to create a subspec and specify search paths for each of the SDKs giving me issues. Here:
s.subspec "Heyzap" do |ss|
ss.dependency "Heyzap", "~> 6.4.4"
ss.xcconfig = { "FRAMEWORK_SEARCH_PATHS" => "$(PODS_ROOT)/Heyzap"}
end
s.subspec "RevMob" do |ss|
ss.dependency "RevMob", "~> 7.4.8"
ss.xcconfig = { "FRAMEWORK_SEARCH_PATHS" => "$(PODS_ROOT)/RevMob"}
end
My pod spec lint now runs & builds without error.

Resources