Cannot build manual ref count CocoaPod - ios

I have an iOS CocoaPod that is a couple of years old as a pod, and several years older than that as a reusable component. Previously built with older versions of Xcode. It was developed with and remains "manual reference counting". I am now trying to import it into a "new" project (actually reconstructed from an old project and also manual reference counting), but I cannot get it to build.
As I said, the enclosing project is manual reference counting and compiles OK that way with no pods installed. "Automatic Reference Counting" is set to "No" in "Build Settings".
However, even though the exact same Build Settings "No" value is present in the pods project, it always generates a compile script with -fobjc-arc, and calls to retain and release are flagged as errors. (Eg, error: 'release' is unavailable: not available in automatic reference counting mode.)
The version of Xcode is 6.0.1.
The version of pod is 0.34.4 (installed fresh yesterday).
The podspec for the pod in question:
Pod::Spec.new do |s|
s.name = "libXXX"
s.version = "1.0"
s.summary = "Exchange library for XYZ."
s.description = "Static library pod for the XXX framework."
s.homepage = "http://example.com"
s.license = { :type => 'MIT', :text => 'Copyright 2012 XYZ' }
s.author = { "Bill Nye" => "bnye#example.com" }
s.source = { :git => 'https://code.example.com/ios/XXX.git', :tag => '1.0' }
s.platform = :ios
s.source_files = 'StaticLib/Headers/*.h'
s.preserve_paths = 'StaticLib/libXXX.a'
s.library = 'XChangeA'
s.xcconfig = { 'LIBRARY_SEARCH_PATHS' => '$(PODS_ROOT)/libXXX/StaticLib' }
s.dependency 'libSignatureToken'
end
I tried adding s.requires_arc = false to the pod spec (and performing pod update), but nothing changed. I also tried s.compiler_flags = '-fno-objc-arc', with no success.
So, how do I convince Xcode to compile the pod with manual reference counting?
Resolved
Apparently "unrelated" problems during pod update caused it to fail silently without configuring the compile mode info. Running pod update --verbose repeatedly helped smoke out the problems.

You need to use s.requires_arc = false
This is documented here. The default recently changed from false to true. Also this error should appear if you run pod spec lint.

Related

Why do I get a ld:framework not found <frameworkName> build error during pod repo push?

I have a framework that I've built for iOS, dynamic framework with a Universal binary for x86_64 (iosSimulator), arm64 and arm64e.
The framework works fine when I drag it to an app and use it.
Pod repo push works fine when I use a repo on my machine that holds the framework and another specs repo that's on my machine. I created the repos with git init --bare
When I use github and point the spec to the github repo instead of my local repo it fails with ld:framework not found <frameworkName> . When I skip validation and push and and finally use it in an app using the pod file I get the same error, ld:framework not found <frameworkName>.
The only difference is I've moved from my local git repo that holds the framework to one on Github.
Edit:
Pasting podspec below
Pod::Spec.new do |s|
s.name = "frameworkName"
s.version = "0.51.0"
s.summary = "A brief description of frameworkName project."
s.description = <<-DESC
An extended description of frameworkName project.
DESC
s.homepage = "http://your.homepage/here"
s.license = { :type => 'Copyright', :text => <<-LICENSE
Copyright 2018
Permission is granted to...
LICENSE
}
s.author = { "myname" => "" }
s.source = { :git => "<git hub repo>", :tag => "#{s.version}", :branch => "iOS_Framework" }
s.ios.vendored_frameworks = "frameworkName.framework"
s.vendored_frameworks = "frameworkName.framework"
s.ios.deployment_target = '12.0'
s.pod_target_xcconfig = { 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
s.user_target_xcconfig = { 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
end
It ended up being a case sensitivity problem. The framework on the repo was named frameworkName.Framework instead of frameworkName.framework. Worked after I changed it.
Not sure why there wasn't an issue with a local git repo.

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.

Unable to add iOS dependency to Flutter plugin

I am creating a Flutter plugin. But when I am trying to add a dependency to iOS part of the plugin I am not finding any proper guideline for this. I declared the dependency in the podspec file of my plugin. But the dependency is only available in the example/ios through Pod but I want access that dependency in my ios folder of my plugin. This is my podspec:
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'comet_chat'
s.version = '0.0.1'
s.summary = 'A new Flutter plugin.'
s.description = <<-DESC
A new Flutter plugin.
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'email#example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'CometChatPro', '1.4.0'
s.ios.deployment_target = '10.0'
s.preserve_paths = 'CometChatPro.framework'
s.xcconfig = { 'OTHER_LDFLAGS' => '-framework CometChatPro' }
s.vendored_frameworks = 'CometChatPro.framework'
end
I followed this issue but it was of no help. How to solve this issue? How can I get my dependency only for the plugin?
There is no way to "only open the plugin's classes", and the dependencies you add in your podspec are only available to your plugin, unless explicitly made it public.
TL;DR
By design, your iOS Flutter plugin will always run when embedded in a Flutter application project. Also, there is a conflict in your podspec; it should never specify the same framework in both dependency and vendored_frameworks.
If you have a CometChatPro.framework folder, copy it in your plugin's ios/Libraries folder and declare its path in your podspec in vendored_frameworks. Personally, I've never used the dependency specifier but there is an example in the flutter-webrtc plugin's implementation.
Either way, the ios/Classes folder of your plugin does have access to the dependencies that you specify in your ios/plugin_name.podpsec file. It just doesn't "know it" when you edit your plugin in any editor other than Xcode (Visual Studio Code, Android Studio, etc).
To develop the Swift or Objective-C classes for your plugin's iOS implementation, you should :
Open the example's Xcode workspace located at example/ios/Runner.xcworkspace.
Edit your plugin's iOS classes by navigating in Xcode to Pods/Development Pods/plugin_name/../../ios/.symlinks/plugins/plugin_name/ios/Classes
Build your project to fix any compiling errors.
If at this point you still don't have access to the framework in your plugin's iOS classes, it means that it wasn't properly setup by Cocoapods. In that case, you'll need to find which Xcode Build Setting is not properly set and then specify these Build Settings in your plugin's podspec, like so:
s.xcconfig = {
'FRAMEWORK_SEARCH_PATHS' => ['${PODS_TARGET_SRCROOT}/Libraries'],
'HEADER_SEARCH_PATHS' => ["${PODS_ROOT}/../.symlinks/plugins/plugin_name/ios/Libraries/CometChatPro.framework/Headers"
}
This explicitly adds the framework to your plugin target's FRAMEWORK_SEARCH_PATHS, and the framework's Headers path to the HEADER_SEARCH_PATH.
When linking vendored_frameworks, you want to make sure that Cocoapods did successfully embed the framework, and that you are building for the right architectures.

Cannot Lint/Push a Swift Cocoapods podspec

I tried to create my first podspec combining ObjC and Swift code, but I soon stumbled uppon a stubborn error that I cannot solve while uploading
Copying MyLibrary from /Users/lukasschwoebel/Library/Caches/CocoaPods/Pods/External/MyLibrary/540307feb534d63ad9015f3f6452b3ad-be661 to
../../../../../../private/var/folders/2p/_pc_vts51b3_pfydgm7_2n200000gn/T/CocoaPods/Lint/Pods/MyLibrary
- Running pre install hooks
-> MyLibrary (0.1.0)
- ERROR | [iOS] Encountered an unknown error (Pods written in Swift can only be integrated as frameworks; this feature is still in beta. Add use_frameworks! to your Podfile or target to opt into using it. The Swift Pod being used is: MyLibrary) during validation.
Here is the command I use:
pod repo push test-podspecs MyLibrary/MyLibrary.podspec --use-libraries --allow-warnings --verbose
As you might see, this is the minimum untouched sample project from CocoaPods as described here: https://guides.cocoapods.org/making/using-pod-lib-create.html
As I can not even make this sample running, I suspect something wrong with my cocoapods configuration.
I made sure there is no single Objective C line in the pod that is to be uploaded (though in the end, I would like to have a podspec with ObjC and Swift code mixed, but at this time I just want to have a working podspec with Swift).
I cannot even upload this simple pod with pure Swift. I first tried with CocoaPods v0.39.0, then downgraded to 0.38.2 and after that 0.38.0, even 0.36.0. Even with a complete un-install of CocoaPods.
It seems I need to configure something in CocoaPods to be able to upload a Swift podspec? The error I get obviously is during the building-phase of the pod where the Podfile needs use_frameworks! to be included. So how can I make CocoaPods use it while compiling the pod during the podspec verification?
Also, I have Xcode 7.0.1 and OSX 10.10.5 installed and it is Swift 2.0 code.
Thank you in advance!
Here is the complete podspec, adapted from the original created MyLibrary.podspec (and yes, that is a local Podspec-Repo, but that does not cause/change the error)
Pod::Spec.new do |s|
s.name = "MyLibrary"
s.version = "0.1.0"
s.summary = "A short description of MyLibrary."
s.description = 'Sample Description'
s.license = 'MIT'
s.author = { "Luke A." => "ls#mymail.to" }
s.source = { :git => "file:///Users/.../test/MyLibrary/", :tag => s.version.to_s }
s.platform = :ios, '8.0'
s.requires_arc = true
s.source_files = 'Pod/Classes/**/*'
s.resource_bundles = {
'MyLibrary' => ['Pod/Assets/*.png']
}
s.frameworks = 'UIKit'
end
I just found the answer, which seems a little obvious.
The command to upload/push the pod was in a bash-script so I did not always have to type all the flags but just and over the filename/path to the podspec. So in the default bash-script I had the flag --use-libraries which is required for one of my pods.
As I was trying something out and had a typo in the pod repo push .. command I stumbled across the man-page:
--use-libraries
Linter uses static libraries to install the spec
With static libraries, this flag seems to be incompatible with Swift podspecs. Removing that flag lints and pushes my podspec successfully.

Add framework to Embed Frameworks Build Phase in XCode iOS 8 project using CocoaPods

I am trying to figure out how use CocoaPods to add a number of frameworks to the Embed Frameworks Build Phase in XCode. My project uses several vendored frameworks from a private pod repo. I can pod install and build successfully. The frameworks are not being added as Embedded Frameworks, so I will get a runtime error when the application runs. The only way I can fix this is to manually add the frameworks to the build phase manually.
Here is an example pod spec:
Pod::Spec.new do |s|
s.name = "ExampleiOS"
s.version = "1.0.1"
s.summary = "ExampleiOS"
s.homepage = "http://www.example.com"
s.author = { "Example.com" => "" }
s.platform = :ios
s.source = { :git => "ssh://git.example.com:1234/pkg/ExampleiOSFramework", :tag => "1.0.1" }
s.source_files = "ExampleiOS/ExampleiOS.framework/Headers/*.h"
s.vendored_frameworks = "ExampleiOS/ExampleiOS.framework"
s.ios.deployment_target = "8.0"
s.requires_arc = true
s.xcconfig = { 'LIBRARY_SEARCH_PATHS' => '"$(PODS_ROOT)/ExampleiOS"',
'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/Headers/ExampleiOS"' }
s.license = {
:type => "Copyright",
:text => <<-LICENSE
Copyright 2015 Example.com. All rights reserved.
LICENSE
}
end
Is there a way to modify this so the framework will be added to the Embed Frameworks Build Phase?
I was able to solve this problem by using the the latest beta of CocoaPods.
The fix to the embedded framework problem is listed in this bug report.
Hopefully the beta will soon be released.

Resources